From patchwork Thu Feb 3 18:58:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "McAllister, Colin" X-Patchwork-Id: 1588173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=ruaP3XBA; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::103f; helo=mail-pj1-x103f.google.com; envelope-from=swupdate+bncbdhnphwu6ijrbcwm6chqmgqeezrmbwq@googlegroups.com; receiver=) Received: from mail-pj1-x103f.google.com (mail-pj1-x103f.google.com [IPv6:2607:f8b0:4864:20::103f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JqSdV5WmFz9s9c for ; Fri, 4 Feb 2022 05:59:25 +1100 (AEDT) Received: by mail-pj1-x103f.google.com with SMTP id n9-20020a17090a73c900b001b5cafefa27sf2376619pjk.2 for ; Thu, 03 Feb 2022 10:59:25 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1643914762; cv=pass; d=google.com; s=arc-20160816; b=zmlzByKDpv02pRFtt1tfTFfH0c88IsabzszGazwC3nvp/Dp1C30NlUWj/gdyXWwQ+p zkyHhS75jfsRHmYk3n55j5phgRW9qROHo58xpb/zJlZ13fQ5/T2BxAHTf5I/6efIydbC g2Tss6vtaOga8wIjdFSbnYKpc7dCyBLrKyIMB6yUopdMQD9khufMAyMwXCmTZJtpTZG+ heyMzZiUep6viC7DFrw/ko6Bdm9OH/nktTvvwGlLLRQtG6SkDM+w7oBq5mNZUfzTiQu/ wVEyelnL44aUe9msQsTEYo4i2kpLb0DBkUsRjo+A9J/5ucX4IL5FTHH6CObYAASNNt6j l5gw== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:mime-version:message-id :date:subject:cc:to:from:dkim-signature; bh=K+g9OeZDVj7KaBbrouHGbhuMOYiH6Jf0JUpPO2/owcQ=; b=FaLNpIjqNFsxZ3YYZKRcpijeQW4F+N+IA8ZcJ020pFb2pWhTsY9t2ZrqDcCtUUynrR 5sMQpEjV4JPXu97jGxwo6FsFiZ+1ZorAGVd6GbAMX3m2YKI01WxPS47JSj5wrcslSiaO IsCMnJpxy86Uv+6UleDrIo4LcJB0888PNymfYm9Vcv2nahTgIk0YDlu8Y6K66ZarS9n2 Qcnv7KWPE3M2mDNF5Dl/KiSSylud5yWqFFtIYhdBbp7tuOgt2G9h7PYGZKdW1NHwTcTX AcYB8YV5h2+AdEXvY1YK03xR54dysJTSVq41YA1dEHdkqvYqFCsm6184rJRgmAbmtwGh YPBw== ARC-Authentication-Results: i=3; gmr-mx.google.com; dkim=pass header.i=@garmin.com header.s=pps1 header.b=YbYgDbNE; dkim=pass header.i=@garmin.onmicrosoft.com header.s=selector1-garmin-onmicrosoft-com header.b=GHL+Cm9f; arc=pass (i=1 spf=pass spfdomain=garmin.com dmarc=pass fromdomain=garmin.com); spf=pass (google.com: domain of colin.mcallister@garmin.com designates 205.220.165.212 as permitted sender) smtp.mailfrom=Colin.McAllister@garmin.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=garmin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=K+g9OeZDVj7KaBbrouHGbhuMOYiH6Jf0JUpPO2/owcQ=; b=ruaP3XBAR11r4L9n9179ITpRFUlec8OWURiYplRJx7leOA0+sde8CUZIUerMOaRVNS w8zstV5pR/pzsCIE3/kCysOsm9w8EGdiKG9UlGDOWoNgYszikVBI3EQ+mG0CjDbu2v3Z RcHRXACKRbIpUx0EqEQwDRb0kpe1FikitVrBivGrfnHulgPSNeDRISBboUCLxyUTNXl0 wRWukW1o7h7KmAsWty6m6ua/75cr2FLXEwXP5IuzNXmZN72vWH4SYcAUL1RGTCZipbF/ 2M/fKFmrtypcqV/8FX8lI5irveNXYh0kgBxbl6kGWbGcIW8kFOhzJ8YoLClhpQm4PACS vXlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=K+g9OeZDVj7KaBbrouHGbhuMOYiH6Jf0JUpPO2/owcQ=; b=T+bIyXHCFJR/rq0mRJzgmVk2GMTdBjWXKReo95aBZL03UWM7Q42J9gJmTd2kD0jtfy Q9K7Ab0zhX5BWfqnljEIhZYvCjkyvkdcEJBiencFwIhARl75+jdi3wx28YblhEzbu9NA SO0Paz/UzYh06UkyNg5eeVzwVPJizE6QM2wfnVD2u8f1FmwTbhNhrH4/nBPonQqYw/dM x5ybkYRz6GUOK8Ja7WNjPWFWKX6X9RbTniYWjWh1HGb4w8FWZSqxmjvtKPDvX1bHiMOp AxX8oehuwLNlzgVitnqk1JTtDpl4Cug9yTDnapsiPEPBU1oDAm6YciX5OYld6m+ruZ9w ATaw== X-Gm-Message-State: AOAM5314Dsa1giduvS1VxY8xH0SsvKVk5L+fLusguthjp7GESJRbC1fA /Bt/R2XYGkQNUvgCPVo4gpo= X-Google-Smtp-Source: ABdhPJyzE+kp4VrSst8IxQ1nqOwACtmq8/OUBtcnwBIlcp2loCFt2gV5gfJGt44hmLBLgCpNGM2NGw== X-Received: by 2002:a17:90a:f001:: with SMTP id bt1mr15199011pjb.109.1643914762328; Thu, 03 Feb 2022 10:59:22 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a17:902:ec88:: with SMTP id x8ls19053541plg.5.gmail; Thu, 03 Feb 2022 10:59:21 -0800 (PST) X-Received: by 2002:a17:902:c702:: with SMTP id p2mr36427793plp.140.1643914761706; Thu, 03 Feb 2022 10:59:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1643914761; cv=pass; d=google.com; s=arc-20160816; b=jIqjJ4z9qEBjmpfeWVj1pYfRAzhWwqpiu4gbI5dVJjQfD2DXQkOyfpVZCEaPGVamB7 jGaFDDpch1XFBrRVIiKAhU7WmHtyIRMp4QzZpB6XLVgqW4dezNiEmOelK652wwaeJNU+ EMVtmg/sjcH2nf80/hvN4GWD4GZUOIeSGU3DYOQxuTpBhMlKWC3qwEUJ+ePwMJX9vf1a 0bTvmrKMDRKpGZByNTBy7eHc7kNN1TrD+SdVuaRLrY/F5h4Maz2vTVxQpQzrcWMAy/j5 Nvqv6PbGRtc2CdaSCUrhXwddcaKFzzkaK89IodKNHMlTvP5IfYGKlK6n92zzrQaRCzaV fr5g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature:dkim-signature; bh=LM8kqpIQ4d/9/u7LE1LpRMkKH2OH/JQoZLUlofbuUuE=; b=DZCdrmISTkbNj9YRA5o+rdj1b6hcw/LnFkyxcqKQvGEilsT4OdgeHxuAV7YyS4Aw+s ABGBfFIztKbodydL3mKErRfA7sgRpGNh2bkRr6R9vHvyZcEJX1/psJvT9FDgcefftC4/ bmnOb8cuqIb9QmeNLuh+ErjuLO/Dnac2mFOfROBdoRBI6/MHDCq0Pd1XhB+MDS6PxBs1 H84Gc+Qv/5c6vTPBQz0VvitpGIjAIfV0ZFTeWVVVdinsi/sH8ZlFX3iKfz4p8jBD3mMi L2xtQe0DIHHY3V4FSbIEnX7qg+FW7nJ5H96TPpjZJh37G97qKH0SgX14lNzktkAR+omU oObg== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@garmin.com header.s=pps1 header.b=YbYgDbNE; dkim=pass header.i=@garmin.onmicrosoft.com header.s=selector1-garmin-onmicrosoft-com header.b=GHL+Cm9f; arc=pass (i=1 spf=pass spfdomain=garmin.com dmarc=pass fromdomain=garmin.com); spf=pass (google.com: domain of colin.mcallister@garmin.com designates 205.220.165.212 as permitted sender) smtp.mailfrom=Colin.McAllister@garmin.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=garmin.com Received: from mx0a-000eb902.pphosted.com (mx0a-000eb902.pphosted.com. [205.220.165.212]) by gmr-mx.google.com with ESMTPS id bf4si629078pjb.3.2022.02.03.10.59.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Feb 2022 10:59:21 -0800 (PST) Received-SPF: pass (google.com: domain of colin.mcallister@garmin.com designates 205.220.165.212 as permitted sender) client-ip=205.220.165.212; Received: from pps.filterd (m0220296.ppops.net [127.0.0.1]) by mx0a-000eb902.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 213Iwn3Y013352 for ; Thu, 3 Feb 2022 12:59:20 -0600 Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by mx0a-000eb902.pphosted.com (PPS) with ESMTPS id 3dy3m1ccdg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 03 Feb 2022 12:59:20 -0600 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RQ1zcEufMQebZJ3g8e1HdPs2JBfndmAiurxYKn5thcrR/scENiolo5w7d5BcqrTD4j6XMuYl2vXoV49yeJpN2mMxMjGU4oM5CbQc/NysvhSCY0uVZoslsWuYX535FupktgfkQ2dR2aL7yXvPdvrxD5sd/g/arfs1KVRPMS2PT+MVBR/mfUJsamdVzJLF/EMtQjRKFCUh3eFgsrDjoDWQqUfAxMPJfEl3iqyWW9KxAcpUr2T8ZlRB4LjIPgorCD9jY0rAVWO2CRefpqg4hHDClGIaqdVcA9ijYfOceFa378DQHyhLx1pxCaZ47BCXdIm7o6DD7uXCkLHsgu/DdBX9Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LM8kqpIQ4d/9/u7LE1LpRMkKH2OH/JQoZLUlofbuUuE=; b=Qp6SR86F03ulDS5AmKLDT0rrBKzaYUlh12rt+3rZm7/u30T2li/7N5YRzcNuBADFTxJbA0ygEUrSQgsFr0EvHW/asu4Rw8lksW2qP/5uIbS09MXPKnphrF7zPWrQ30ZGjY6yPMPwrxblD7WimjTodPPXJZR/3T0ZlM192HncRCVH0ig6gnywMbxmsZ2kLsPEWj9xLgMoDxkKsyEI+TQjCsXPQode2iSph/656tI2gSL2ZE9gg9mBdF10g3cWOuaFgOlXKv3KcdR9eFnbedoiN/CO7xTMUXO0j0HT1tt2Ev9PWF2vnvrzv1+B1Ztwb1Dih/NiTLFdX2QZuZzVJxIaBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 204.77.163.244) smtp.rcpttodomain=googlegroups.com smtp.mailfrom=garmin.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=garmin.com; dkim=none (message not signed); arc=none Received: from BN6PR1701CA0003.namprd17.prod.outlook.com (2603:10b6:405:15::13) by MN2PR04MB6256.namprd04.prod.outlook.com (2603:10b6:208:e4::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Thu, 3 Feb 2022 18:59:17 +0000 Received: from BN7NAM10FT004.eop-nam10.prod.protection.outlook.com (2603:10b6:405:15:cafe::60) by BN6PR1701CA0003.outlook.office365.com (2603:10b6:405:15::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.14 via Frontend Transport; Thu, 3 Feb 2022 18:59:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 204.77.163.244) smtp.mailfrom=garmin.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=garmin.com; Received-SPF: Pass (protection.outlook.com: domain of garmin.com designates 204.77.163.244 as permitted sender) receiver=protection.outlook.com; client-ip=204.77.163.244; helo=edgetransport.garmin.com; Received: from edgetransport.garmin.com (204.77.163.244) by BN7NAM10FT004.mail.protection.outlook.com (10.13.157.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 18:59:17 +0000 Received: from cv1wpa-exmb3.ad.garmin.com (10.5.144.73) by olawpa-edge1.garmin.com (10.60.4.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2106.2; Thu, 3 Feb 2022 12:59:14 -0600 Received: from OLAWPA-EXMB3.ad.garmin.com (10.5.144.15) by cv1wpa-exmb3.ad.garmin.com (10.5.144.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2375.18; Thu, 3 Feb 2022 12:59:16 -0600 Received: from ola-jnrkg73.ad.garmin.com (10.5.209.17) by smtp.garmin.com (10.5.144.15) with Microsoft SMTP Server id 15.1.2375.18 via Frontend Transport; Thu, 3 Feb 2022 12:59:16 -0600 X-Patchwork-Original-From: "'Colin McAllister' via swupdate" From: "McAllister, Colin" To: CC: Colin McAllister Subject: [swupdate] [PATCH] raw_handler: Add atomic-install support Date: Thu, 3 Feb 2022 12:58:56 -0600 Message-ID: <20220203185856.28649-1-colin.mcallister@garmin.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c5532f1a-b0a0-4a00-9d80-08d9e7474763 X-MS-TrafficTypeDiagnostic: MN2PR04MB6256:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1751; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: krqcrfpG7nohxyS/0iPOcZyshkJyqGRiw8dPdx44ucNuIqJsioo1SkX+xJJS4s3U4o0JAUv+qpJBvODAzk6rRAq19FoGqJViRzu33fJL5t9NN2xpvX8sxX+ytEUiouL2ObEA9FSpufEfpUZSSvXmQk7uJSztYnIl7FInn8DcPgobU8VezMHofo258BjqqyDs61a48dQNoiRv4/qMZwRWSX/RVCFQjDl65VdJwTi/tfItdEnTR8SSEARGYsUal+nuKsKC+D9loJbVWe0FBHkUt66PAhmPYYRHq4xiedwzzwfjb91nHd+13vX2Ty4dbTe1ZzJemP5ucckXTewG/IDSEQm3RNjrr5SrmdH8afxLFbSoNeIzggHMm95kPBBrQzo0KFEyvj8336G4JKZlbJDFTQknYTcvyMUb+P7DyWvimIpvFO+wub4jGsCthWI752nPinjHsX/p9LzGSRE6RAugg4yjhh93N/Z5FXxAMBZw7S9KapETEFAO1VIYFGaKCaidaWS33PxdzLpZRqGvWloqpV39a7pM3Lx41/imRDQMwD+8djxnuKMK69UGkhwzzD713r44XWq5FeHSz0PRlCOdHrUilWgBUrgfzDNorjKvAnBgffHjdEH3fEZOLGsAeowelWUs1P8NeXiXEkBxs2+jkZZe5CpZIEOJzGLDNAkLoUw+vbryBd1qsgUG3Bg+8nKT X-Forefront-Antispam-Report: CIP:204.77.163.244;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:edgetransport.garmin.com;PTR:extedge.garmin.com;CAT:NONE;SFS:(13230001)(36840700001)(40470700004)(46966006)(186003)(83380400001)(6916009)(356005)(1076003)(26005)(7636003)(36756003)(316002)(8676002)(70586007)(5660300002)(70206006)(2906002)(336012)(8936002)(47076005)(107886003)(82310400004)(40460700003)(6666004)(508600001)(426003)(7696005)(4326008)(36860700001)(2616005)(86362001);DIR:OUT;SFP:1102; X-OriginatorOrg: garmin.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 18:59:17.4947 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c5532f1a-b0a0-4a00-9d80-08d9e7474763 X-MS-Exchange-CrossTenant-Id: 38d0d425-ba52-4c0a-a03e-2a65c8e82e2d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=38d0d425-ba52-4c0a-a03e-2a65c8e82e2d;Ip=[204.77.163.244];Helo=[edgetransport.garmin.com] X-MS-Exchange-CrossTenant-AuthSource: BN7NAM10FT004.eop-nam10.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR04MB6256 X-Proofpoint-ORIG-GUID: uFzWO3TtAwktrd1OoHN8sxTMByHpYcNK X-Proofpoint-GUID: uFzWO3TtAwktrd1OoHN8sxTMByHpYcNK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-03_06,2022-02-03_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 suspectscore=0 lowpriorityscore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 priorityscore=1501 clxscore=1015 adultscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202030115 X-Original-Sender: colin.mcallister@garmin.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@garmin.com header.s=pps1 header.b=YbYgDbNE; dkim=pass header.i=@garmin.onmicrosoft.com header.s=selector1-garmin-onmicrosoft-com header.b=GHL+Cm9f; arc=pass (i=1 spf=pass spfdomain=garmin.com dmarc=pass fromdomain=garmin.com); spf=pass (google.com: domain of colin.mcallister@garmin.com designates 205.220.165.212 as permitted sender) smtp.mailfrom=Colin.McAllister@garmin.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=garmin.com X-Original-From: Colin McAllister Reply-To: Colin McAllister Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Add property for raw file handler that installs file to .tmp file. Once the .tmp file is installed, it is atomically renamed to the specified file in path. This ensures that a partial install does not affect the currently installed file. Signed-off-by: Colin McAllister --- doc/source/sw-description.rst | 7 +++++++ handlers/raw_handler.c | 28 +++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst index 3de3636..6901a72 100644 --- a/doc/source/sw-description.rst +++ b/doc/source/sw-description.rst @@ -738,6 +738,13 @@ As a general rule, swupdate doesn't copy out a file if the destination path doesn't exists. This behavior could be changed using the special property "create-destination". +As another general rule, swupdate installs the file directly to the specified +path. If the destination file is intended to be atomically installed, the +special property "atomic-install" may be set to "true". This installs the +file to the specified path with ".tmp" apppended to the filename. In the case +where a file already exists with the specified path, the atomic install prevents +the original file from being overwritten until the temp file is installed. + Scripts ------- diff --git a/handlers/raw_handler.c b/handlers/raw_handler.c index 619a2f4..3fab630 100644 --- a/handlers/raw_handler.c +++ b/handlers/raw_handler.c @@ -206,6 +206,7 @@ static int install_raw_file(struct img_type *img, void __attribute__ ((__unused__)) *data) { char path[255]; + char tmp_path[255]; int fdout; int ret = 0; int use_mount = (strlen(img->device) && strlen(img->filesystem)) ? 1 : 0; @@ -237,6 +238,13 @@ static int install_raw_file(struct img_type *img, } } + if (strtobool(dict_get_value(&img->properties, "atomic-install"))) { + if (snprintf(tmp_path, sizeof(path), "%s%s", img->path, ".tmp") >= (int)sizeof(path)) { + ERROR("Temp path too long: %s%s", img->path, ".tmp"); + return -1; + } + } + TRACE("Installing file %s on %s", img->fname, path); @@ -249,7 +257,12 @@ static int install_raw_file(struct img_type *img, } } - fdout = openfileoutput(path); + if (strtobool(dict_get_value(&img->properties, "atomic-install"))) { + fdout = openfileoutput(tmp_path); + } + else { + fdout = openfileoutput(path); + } if (fdout < 0) return fdout; if (!img_check_free_space(img, fdout)) { @@ -260,8 +273,21 @@ static int install_raw_file(struct img_type *img, if (ret< 0) { ERROR("Error copying extracted file"); } + + if (strtobool(dict_get_value(&img->properties, "atomic-install"))) { + if(fsync(fdout)) { + ERROR("Error writing %s to disk: %s", tmp_path, strerror(errno)); + } + } + close(fdout); + if (strtobool(dict_get_value(&img->properties, "atomic-install"))) { + if(rename(tmp_path, path)) { + ERROR("Error renaming %s to %s: %s", tmp_path, path, strerror(errno)); + } + } + if (use_mount) { swupdate_umount(DATADST_DIR); }