44 * SPDX-License-Identifier: Apache-2.0
55 */
66
7- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
7+ #[ cfg( any(
8+ target_arch = "x86_64" ,
9+ target_arch = "aarch64" ,
10+ target_arch = "riscv64"
11+ ) ) ]
812use anyhow:: { bail, Context , Result } ;
9- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
13+ #[ cfg( any(
14+ target_arch = "x86_64" ,
15+ target_arch = "aarch64" ,
16+ target_arch = "riscv64"
17+ ) ) ]
1018use camino:: { Utf8Path , Utf8PathBuf } ;
11- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
19+ #[ cfg( any(
20+ target_arch = "x86_64" ,
21+ target_arch = "aarch64" ,
22+ target_arch = "riscv64"
23+ ) ) ]
1224use openat_ext:: OpenatDirExt ;
13- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
25+ #[ cfg( any(
26+ target_arch = "x86_64" ,
27+ target_arch = "aarch64" ,
28+ target_arch = "riscv64"
29+ ) ) ]
1430use openssl:: hash:: { Hasher , MessageDigest } ;
1531use rustix:: fd:: BorrowedFd ;
1632use serde:: { Deserialize , Serialize } ;
1733#[ allow( unused_imports) ]
1834use std:: collections:: { BTreeMap , HashMap , HashSet } ;
1935use std:: fmt:: Display ;
20- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
36+ #[ cfg( any(
37+ target_arch = "x86_64" ,
38+ target_arch = "aarch64" ,
39+ target_arch = "riscv64"
40+ ) ) ]
2141use std:: os:: unix:: io:: AsRawFd ;
2242use std:: os:: unix:: process:: CommandExt ;
2343use std:: process:: Command ;
2444
2545/// The prefix we apply to our temporary files.
26- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
46+ #[ cfg( any(
47+ target_arch = "x86_64" ,
48+ target_arch = "aarch64" ,
49+ target_arch = "riscv64"
50+ ) ) ]
2751pub ( crate ) const TMP_PREFIX : & str = ".btmp." ;
2852// This module doesn't handle modes right now, because
2953// we're only targeting FAT filesystems for UEFI.
3054// In FAT there are no unix permission bits, usually
3155// they're set by mount options.
3256// See also https://github.com/coreos/fedora-coreos-config/commit/8863c2b34095a2ae5eae6fbbd121768a5f592091
33- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
57+ #[ cfg( any(
58+ target_arch = "x86_64" ,
59+ target_arch = "aarch64" ,
60+ target_arch = "riscv64"
61+ ) ) ]
3462const DEFAULT_FILE_MODE : u32 = 0o700 ;
3563
3664use crate :: sha512string:: SHA512String ;
@@ -79,7 +107,11 @@ impl FileTreeDiff {
79107}
80108
81109impl FileMetadata {
82- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
110+ #[ cfg( any(
111+ target_arch = "x86_64" ,
112+ target_arch = "aarch64" ,
113+ target_arch = "riscv64"
114+ ) ) ]
83115 pub ( crate ) fn new_from_path < P : openat:: AsPath > (
84116 dir : & openat:: Dir ,
85117 name : P ,
@@ -99,7 +131,11 @@ impl FileMetadata {
99131
100132impl FileTree {
101133 // Internal helper to generate a sub-tree
102- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
134+ #[ cfg( any(
135+ target_arch = "x86_64" ,
136+ target_arch = "aarch64" ,
137+ target_arch = "riscv64"
138+ ) ) ]
103139 fn unsorted_from_dir ( dir : & openat:: Dir ) -> Result < HashMap < String , FileMetadata > > {
104140 let mut ret = HashMap :: new ( ) ;
105141 for entry in dir. list_dir ( "." ) ? {
@@ -136,7 +172,11 @@ impl FileTree {
136172 }
137173
138174 /// Create a FileTree from the target directory.
139- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
175+ #[ cfg( any(
176+ target_arch = "x86_64" ,
177+ target_arch = "aarch64" ,
178+ target_arch = "riscv64"
179+ ) ) ]
140180 pub ( crate ) fn new_from_dir ( dir : & openat:: Dir ) -> Result < Self > {
141181 let mut children = BTreeMap :: new ( ) ;
142182 for ( k, v) in Self :: unsorted_from_dir ( dir) ?. drain ( ) {
@@ -147,7 +187,11 @@ impl FileTree {
147187 }
148188
149189 /// Determine the changes *from* self to the updated tree
150- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
190+ #[ cfg( any(
191+ target_arch = "x86_64" ,
192+ target_arch = "aarch64" ,
193+ target_arch = "riscv64"
194+ ) ) ]
151195 pub ( crate ) fn diff ( & self , updated : & Self ) -> Result < FileTreeDiff > {
152196 self . diff_impl ( updated, true )
153197 }
@@ -167,7 +211,11 @@ impl FileTree {
167211 current. diff_impl ( self , false )
168212 }
169213
170- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
214+ #[ cfg( any(
215+ target_arch = "x86_64" ,
216+ target_arch = "aarch64" ,
217+ target_arch = "riscv64"
218+ ) ) ]
171219 fn diff_impl ( & self , updated : & Self , check_additions : bool ) -> Result < FileTreeDiff > {
172220 let mut additions = HashSet :: new ( ) ;
173221 let mut removals = HashSet :: new ( ) ;
@@ -199,7 +247,11 @@ impl FileTree {
199247
200248 /// Create a diff from a target directory. This will ignore
201249 /// any files or directories that are not part of the original tree.
202- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
250+ #[ cfg( any(
251+ target_arch = "x86_64" ,
252+ target_arch = "aarch64" ,
253+ target_arch = "riscv64"
254+ ) ) ]
203255 pub ( crate ) fn relative_diff_to ( & self , dir : & openat:: Dir ) -> Result < FileTreeDiff > {
204256 let mut removals = HashSet :: new ( ) ;
205257 let mut changes = HashSet :: new ( ) ;
@@ -233,7 +285,11 @@ impl FileTree {
233285}
234286
235287// Recursively remove all files/dirs in the directory that start with our TMP_PREFIX
236- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
288+ #[ cfg( any(
289+ target_arch = "x86_64" ,
290+ target_arch = "aarch64" ,
291+ target_arch = "riscv64"
292+ ) ) ]
237293fn cleanup_tmp ( dir : & openat:: Dir ) -> Result < ( ) > {
238294 for entry in dir. list_dir ( "." ) ? {
239295 let entry = entry?;
@@ -264,7 +320,11 @@ fn cleanup_tmp(dir: &openat::Dir) -> Result<()> {
264320}
265321
266322#[ derive( Default , Clone ) ]
267- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
323+ #[ cfg( any(
324+ target_arch = "x86_64" ,
325+ target_arch = "aarch64" ,
326+ target_arch = "riscv64"
327+ ) ) ]
268328pub ( crate ) struct ApplyUpdateOptions {
269329 pub ( crate ) skip_removals : bool ,
270330 pub ( crate ) skip_sync : bool ,
@@ -274,7 +334,11 @@ pub(crate) struct ApplyUpdateOptions {
274334// to be bound in nix today. I found https://github.com/XuShaohua/nc
275335// but that's a nontrivial dependency with not a lot of code review.
276336// Let's just fork off a helper process for now.
277- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
337+ #[ cfg( any(
338+ target_arch = "x86_64" ,
339+ target_arch = "aarch64" ,
340+ target_arch = "riscv64"
341+ ) ) ]
278342pub ( crate ) fn syncfs ( d : & openat:: Dir ) -> Result < ( ) > {
279343 use rustix:: fs:: { Mode , OFlags } ;
280344 let d = unsafe { BorrowedFd :: borrow_raw ( d. as_raw_fd ( ) ) } ;
@@ -284,7 +348,11 @@ pub(crate) fn syncfs(d: &openat::Dir) -> Result<()> {
284348}
285349
286350/// Copy from src to dst at root dir
287- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
351+ #[ cfg( any(
352+ target_arch = "x86_64" ,
353+ target_arch = "aarch64" ,
354+ target_arch = "riscv64"
355+ ) ) ]
288356fn copy_dir ( root : & openat:: Dir , src : & str , dst : & str ) -> Result < ( ) > {
289357 use bootc_utils:: CommandRunExt ;
290358
@@ -304,7 +372,11 @@ fn copy_dir(root: &openat::Dir, src: &str, dst: &str) -> Result<()> {
304372/// Get first sub dir and tmp sub dir for the path
305373/// "fedora/foo/bar" -> ("fedora", ".btmp.fedora")
306374/// "foo" -> ("foo", ".btmp.foo")
307- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
375+ #[ cfg( any(
376+ target_arch = "x86_64" ,
377+ target_arch = "aarch64" ,
378+ target_arch = "riscv64"
379+ ) ) ]
308380fn get_first_dir ( path : & Utf8Path ) -> Result < ( & Utf8Path , String ) > {
309381 let first = path
310382 . iter ( )
@@ -316,7 +388,11 @@ fn get_first_dir(path: &Utf8Path) -> Result<(&Utf8Path, String)> {
316388}
317389
318390/// Given two directories, apply a diff generated from srcdir to destdir
319- #[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
391+ #[ cfg( any(
392+ target_arch = "x86_64" ,
393+ target_arch = "aarch64" ,
394+ target_arch = "riscv64"
395+ ) ) ]
320396pub ( crate ) fn apply_diff (
321397 srcdir : & openat:: Dir ,
322398 destdir : & openat:: Dir ,
0 commit comments