1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
//! Archive entry types and operations
use crate::error::{Error, Result};
use std::ffi::{CStr, CString};
use std::path::Path;
use std::time::SystemTime;
/// File type of an archive entry
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FileType {
/// Regular file
RegularFile,
/// Directory
Directory,
/// Symbolic link
SymbolicLink,
/// Block device
BlockDevice,
/// Character device
CharacterDevice,
/// FIFO/named pipe
Fifo,
/// Socket
Socket,
/// Unknown type
Unknown,
}
impl FileType {
fn from_mode(mode: u32) -> Self {
const S_IFMT: u32 = 0o170000;
const S_IFREG: u32 = 0o100000;
const S_IFDIR: u32 = 0o040000;
const S_IFLNK: u32 = 0o120000;
const S_IFBLK: u32 = 0o060000;
const S_IFCHR: u32 = 0o020000;
const S_IFIFO: u32 = 0o010000;
const S_IFSOCK: u32 = 0o140000;
match mode & S_IFMT {
S_IFREG => FileType::RegularFile,
S_IFDIR => FileType::Directory,
S_IFLNK => FileType::SymbolicLink,
S_IFBLK => FileType::BlockDevice,
S_IFCHR => FileType::CharacterDevice,
S_IFIFO => FileType::Fifo,
S_IFSOCK => FileType::Socket,
_ => FileType::Unknown,
}
}
fn to_mode(self) -> u32 {
const S_IFREG: u32 = 0o100000;
const S_IFDIR: u32 = 0o040000;
const S_IFLNK: u32 = 0o120000;
const S_IFBLK: u32 = 0o060000;
const S_IFCHR: u32 = 0o020000;
const S_IFIFO: u32 = 0o010000;
const S_IFSOCK: u32 = 0o140000;
match self {
FileType::RegularFile => S_IFREG,
FileType::Directory => S_IFDIR,
FileType::SymbolicLink => S_IFLNK,
FileType::BlockDevice => S_IFBLK,
FileType::CharacterDevice => S_IFCHR,
FileType::Fifo => S_IFIFO,
FileType::Socket => S_IFSOCK,
FileType::Unknown => 0,
}
}
}
/// Immutable reference to an archive entry
///
/// The lifetime parameter ensures the entry cannot outlive the archive
/// and that only one entry can be active at a time (enforced through
/// the mutable borrow of the archive when calling next_entry).
pub struct Entry<'a> {
pub(crate) entry: *mut libarchive2_sys::archive_entry,
pub(crate) _marker: std::marker::PhantomData<&'a ()>,
}
impl<'a> Entry<'a> {
/// Get the pathname of the entry
///
/// Returns an owned String to ensure safety, as the underlying C string
/// may be invalidated when the entry is modified or freed.
///
/// This method first tries to get the UTF-8 pathname, but if that fails
/// (which can happen with non-ASCII filenames in certain archive formats),
/// it falls back to the raw pathname and uses lossy UTF-8 conversion.
pub fn pathname(&self) -> Option<String> {
unsafe {
// First try the UTF-8 version
let ptr = libarchive2_sys::archive_entry_pathname_utf8(self.entry);
if !ptr.is_null()
&& let Ok(s) = CStr::from_ptr(ptr).to_str()
{
return Some(s.to_owned());
}
// Fall back to the raw pathname with lossy conversion
let ptr = libarchive2_sys::archive_entry_pathname(self.entry);
if ptr.is_null() {
None
} else {
Some(CStr::from_ptr(ptr).to_string_lossy().into_owned())
}
}
}
/// Get the file type
pub fn file_type(&self) -> FileType {
unsafe {
let mode = libarchive2_sys::archive_entry_filetype(self.entry);
FileType::from_mode(mode as u32)
}
}
/// Get the file size in bytes
pub fn size(&self) -> i64 {
unsafe { libarchive2_sys::archive_entry_size(self.entry) }
}
/// Get the file permissions (mode)
pub fn mode(&self) -> u32 {
unsafe { libarchive2_sys::archive_entry_perm(self.entry) as u32 }
}
/// Get the modification time
pub fn mtime(&self) -> Option<SystemTime> {
unsafe {
let sec = libarchive2_sys::archive_entry_mtime(self.entry);
let nsec = libarchive2_sys::archive_entry_mtime_nsec(self.entry);
if sec >= 0 {
Some(SystemTime::UNIX_EPOCH + std::time::Duration::new(sec as u64, nsec as u32))
} else {
None
}
}
}
/// Get the user ID
pub fn uid(&self) -> Option<u64> {
unsafe {
if libarchive2_sys::archive_entry_uid_is_set(self.entry) != 0 {
Some(libarchive2_sys::archive_entry_uid(self.entry) as u64)
} else {
None
}
}
}
/// Get the group ID
pub fn gid(&self) -> Option<u64> {
unsafe {
if libarchive2_sys::archive_entry_gid_is_set(self.entry) != 0 {
Some(libarchive2_sys::archive_entry_gid(self.entry) as u64)
} else {
None
}
}
}
/// Get the user name
///
/// Returns an owned String to ensure safety, as the underlying C string
/// may be invalidated when the entry is modified or freed.
pub fn uname(&self) -> Option<String> {
unsafe {
// First try the UTF-8 version
let ptr = libarchive2_sys::archive_entry_uname_utf8(self.entry);
if !ptr.is_null()
&& let Ok(s) = CStr::from_ptr(ptr).to_str()
{
return Some(s.to_owned());
}
// Fall back to the raw uname with lossy conversion
let ptr = libarchive2_sys::archive_entry_uname(self.entry);
if ptr.is_null() {
None
} else {
Some(CStr::from_ptr(ptr).to_string_lossy().into_owned())
}
}
}
/// Get the group name
///
/// Returns an owned String to ensure safety, as the underlying C string
/// may be invalidated when the entry is modified or freed.
pub fn gname(&self) -> Option<String> {
unsafe {
// First try the UTF-8 version
let ptr = libarchive2_sys::archive_entry_gname_utf8(self.entry);
if !ptr.is_null()
&& let Ok(s) = CStr::from_ptr(ptr).to_str()
{
return Some(s.to_owned());
}
// Fall back to the raw gname with lossy conversion
let ptr = libarchive2_sys::archive_entry_gname(self.entry);
if ptr.is_null() {
None
} else {
Some(CStr::from_ptr(ptr).to_string_lossy().into_owned())
}
}
}
/// Get the symlink target (for symbolic links)
///
/// Returns an owned String to ensure safety, as the underlying C string
/// may be invalidated when the entry is modified or freed.
pub fn symlink(&self) -> Option<String> {
unsafe {
// First try the UTF-8 version
let ptr = libarchive2_sys::archive_entry_symlink_utf8(self.entry);
if !ptr.is_null()
&& let Ok(s) = CStr::from_ptr(ptr).to_str()
{
return Some(s.to_owned());
}
// Fall back to the raw symlink with lossy conversion
let ptr = libarchive2_sys::archive_entry_symlink(self.entry);
if ptr.is_null() {
None
} else {
Some(CStr::from_ptr(ptr).to_string_lossy().into_owned())
}
}
}
/// Get the hardlink target
///
/// Returns an owned String to ensure safety, as the underlying C string
/// may be invalidated when the entry is modified or freed.
pub fn hardlink(&self) -> Option<String> {
unsafe {
// First try the UTF-8 version
let ptr = libarchive2_sys::archive_entry_hardlink_utf8(self.entry);
if !ptr.is_null()
&& let Ok(s) = CStr::from_ptr(ptr).to_str()
{
return Some(s.to_owned());
}
// Fall back to the raw hardlink with lossy conversion
let ptr = libarchive2_sys::archive_entry_hardlink(self.entry);
if ptr.is_null() {
None
} else {
Some(CStr::from_ptr(ptr).to_string_lossy().into_owned())
}
}
}
/// Get the access time
pub fn atime(&self) -> Option<SystemTime> {
unsafe {
let sec = libarchive2_sys::archive_entry_atime(self.entry);
let nsec = libarchive2_sys::archive_entry_atime_nsec(self.entry);
if sec >= 0 {
Some(SystemTime::UNIX_EPOCH + std::time::Duration::new(sec as u64, nsec as u32))
} else {
None
}
}
}
/// Get the creation time (birth time)
///
/// Note: Not all archive formats and filesystems support birth time.
pub fn birthtime(&self) -> Option<SystemTime> {
unsafe {
let sec = libarchive2_sys::archive_entry_birthtime(self.entry);
let nsec = libarchive2_sys::archive_entry_birthtime_nsec(self.entry);
if sec >= 0 {
Some(SystemTime::UNIX_EPOCH + std::time::Duration::new(sec as u64, nsec as u32))
} else {
None
}
}
}
/// Get the status change time
pub fn ctime(&self) -> Option<SystemTime> {
unsafe {
let sec = libarchive2_sys::archive_entry_ctime(self.entry);
let nsec = libarchive2_sys::archive_entry_ctime_nsec(self.entry);
if sec >= 0 {
Some(SystemTime::UNIX_EPOCH + std::time::Duration::new(sec as u64, nsec as u32))
} else {
None
}
}
}
/// Get the device number (for block and character devices)
pub fn dev(&self) -> Option<u64> {
unsafe {
if libarchive2_sys::archive_entry_dev_is_set(self.entry) != 0 {
Some(libarchive2_sys::archive_entry_dev(self.entry) as u64)
} else {
None
}
}
}
/// Get the device major number
///
/// Returns the device major number. For entries without a device,
/// this may return 0 or an undefined value.
pub fn devmajor(&self) -> u64 {
unsafe { libarchive2_sys::archive_entry_devmajor(self.entry) as u64 }
}
/// Get the device minor number
///
/// Returns the device minor number. For entries without a device,
/// this may return 0 or an undefined value.
pub fn devminor(&self) -> u64 {
unsafe { libarchive2_sys::archive_entry_devminor(self.entry) as u64 }
}
/// Get the inode number
///
/// Returns the inode number. If not set, returns 0.
pub fn ino(&self) -> u64 {
unsafe { libarchive2_sys::archive_entry_ino64(self.entry) as u64 }
}
/// Get the number of hard links
///
/// Returns the number of hard links. If not set, returns 0.
pub fn nlink(&self) -> u32 {
unsafe { libarchive2_sys::archive_entry_nlink(self.entry) as u32 }
}
/// Get the device ID (for the filesystem containing the file)
///
/// Returns the device ID. For entries without a device,
/// this may return 0 or an undefined value.
pub fn rdev(&self) -> u64 {
unsafe { libarchive2_sys::archive_entry_rdev(self.entry) as u64 }
}
/// Get the major device number (for the filesystem containing the file)
///
/// Returns the major device number. For entries without a device,
/// this may return 0 or an undefined value.
pub fn rdevmajor(&self) -> u64 {
unsafe { libarchive2_sys::archive_entry_rdevmajor(self.entry) as u64 }
}
/// Get the minor device number (for the filesystem containing the file)
///
/// Returns the minor device number. For entries without a device,
/// this may return 0 or an undefined value.
pub fn rdevminor(&self) -> u64 {
unsafe { libarchive2_sys::archive_entry_rdevminor(self.entry) as u64 }
}
/// Get file flags (BSD-style file flags)
///
/// Returns a tuple of (set flags, clear flags)
pub fn fflags(&self) -> Option<(u64, u64)> {
unsafe {
let mut set: std::os::raw::c_ulong = 0;
let mut clear: std::os::raw::c_ulong = 0;
libarchive2_sys::archive_entry_fflags(self.entry, &mut set, &mut clear);
Some((set as u64, clear as u64))
}
}
/// Get file flags as a text string
///
/// Returns an owned String to ensure safety, as the underlying C string
/// may be invalidated when the entry is modified or freed.
pub fn fflags_text(&self) -> Option<String> {
unsafe {
let ptr = libarchive2_sys::archive_entry_fflags_text(self.entry);
if ptr.is_null() {
None
} else {
CStr::from_ptr(ptr).to_str().ok().map(|s| s.to_owned())
}
}
}
/// Check if entry is encrypted
pub fn is_encrypted(&self) -> bool {
unsafe { libarchive2_sys::archive_entry_is_encrypted(self.entry) != 0 }
}
/// Check if entry data is encrypted
pub fn is_data_encrypted(&self) -> bool {
unsafe { libarchive2_sys::archive_entry_is_data_encrypted(self.entry) != 0 }
}
/// Check if entry metadata is encrypted
pub fn is_metadata_encrypted(&self) -> bool {
unsafe { libarchive2_sys::archive_entry_is_metadata_encrypted(self.entry) != 0 }
}
}
/// Mutable reference to an archive entry for building/writing
pub struct EntryMut {
pub(crate) entry: *mut libarchive2_sys::archive_entry,
pub(crate) owned: bool,
}
impl EntryMut {
/// Create a new entry
pub fn new() -> Self {
unsafe {
let entry = libarchive2_sys::archive_entry_new();
EntryMut { entry, owned: true }
}
}
/// Set the pathname
pub fn set_pathname<P: AsRef<Path>>(&mut self, path: P) -> Result<()> {
let path_str = path
.as_ref()
.to_str()
.ok_or_else(|| Error::InvalidArgument("Path contains invalid UTF-8".to_string()))?;
let c_path = CString::new(path_str)
.map_err(|_| Error::InvalidArgument("Path contains null byte".to_string()))?;
unsafe {
libarchive2_sys::archive_entry_set_pathname_utf8(self.entry, c_path.as_ptr());
}
Ok(())
}
/// Set the file type
pub fn set_file_type(&mut self, file_type: FileType) {
// SAFETY: entry is a valid pointer and file_type.to_mode() returns a valid mode value
unsafe {
libarchive2_sys::archive_entry_set_filetype(self.entry, file_type.to_mode());
}
}
/// Set the file size
pub fn set_size(&mut self, size: i64) {
// SAFETY: entry is a valid pointer
unsafe {
libarchive2_sys::archive_entry_set_size(self.entry, size);
}
}
/// Set the file permissions
///
/// On platforms where permissions are stored as u16 (macOS, Windows, BSD),
/// this will return an error if perm > 0xFFFF. Standard Unix permissions
/// (0o777) are always safe on all platforms.
///
/// # Platform Notes
///
/// The underlying `mode_t` type varies by platform:
/// - Linux (64-bit): u32
/// - macOS/BSD/Windows: u16
/// - Android: varies by architecture (u32 on 64-bit, u16 on 32-bit)
pub fn set_perm(&mut self, perm: u32) -> Result<()> {
unsafe {
// Note: This platform detection is conservative. It assumes u32 on 64-bit Linux/Android
// and u16 elsewhere. The libarchive2-sys crate should ideally provide type information
// from its build script to make this more accurate.
// Platforms with 32-bit mode_t: Linux and Android on 64-bit architectures
#[cfg(all(
any(target_os = "linux", target_os = "android"),
any(
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "loongarch64",
target_arch = "riscv64"
)
))]
{
libarchive2_sys::archive_entry_set_perm(self.entry, perm);
}
// All other platforms (macOS, BSD, Windows, 32-bit architectures) use 16-bit mode_t
#[cfg(not(all(
any(target_os = "linux", target_os = "android"),
any(
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "loongarch64",
target_arch = "riscv64"
)
)))]
{
// SAFETY: We check that the value fits in u16 to prevent silent truncation
// Standard Unix permissions (0o777 = 0x1FF) always fit in u16
if perm > 0xFFFF {
return Err(Error::InvalidArgument(format!(
"Permission value 0x{:X} exceeds platform maximum 0xFFFF",
perm
)));
}
libarchive2_sys::archive_entry_set_perm(self.entry, perm as u16);
}
}
Ok(())
}
/// Set the modification time
///
/// # Platform Notes
///
/// The underlying time_t type varies by platform:
/// - Most Unix/Linux: i64 seconds, i64 nanoseconds
/// - Windows: i64 seconds, i32 nanoseconds
/// - Android 32-bit: i32 seconds, i32 nanoseconds
pub fn set_mtime(&mut self, time: SystemTime) {
if let Ok(duration) = time.duration_since(SystemTime::UNIX_EPOCH) {
let nsec = duration.subsec_nanos();
unsafe {
// Android 32-bit (armv7, x86) uses i32 for both sec and nsec
#[cfg(all(target_os = "android", any(target_arch = "arm", target_arch = "x86")))]
{
libarchive2_sys::archive_entry_set_mtime(
self.entry,
duration.as_secs() as i32,
nsec as i32,
);
}
// Windows uses i64 sec, i32 nsec
#[cfg(target_os = "windows")]
{
libarchive2_sys::archive_entry_set_mtime(
self.entry,
duration.as_secs() as i64,
nsec as i32,
);
}
// Unix platforms and Android 64-bit use i64 for both
#[cfg(not(any(
target_os = "windows",
all(target_os = "android", any(target_arch = "arm", target_arch = "x86"))
)))]
{
libarchive2_sys::archive_entry_set_mtime(
self.entry,
duration.as_secs() as i64,
nsec as i64,
);
}
}
}
}
/// Set the user ID
pub fn set_uid(&mut self, uid: u64) {
unsafe {
libarchive2_sys::archive_entry_set_uid(self.entry, uid as i64);
}
}
/// Set the group ID
pub fn set_gid(&mut self, gid: u64) {
unsafe {
libarchive2_sys::archive_entry_set_gid(self.entry, gid as i64);
}
}
/// Set the user name
pub fn set_uname(&mut self, uname: &str) -> Result<()> {
let c_uname = CString::new(uname)
.map_err(|_| Error::InvalidArgument("Username contains null byte".to_string()))?;
unsafe {
libarchive2_sys::archive_entry_set_uname_utf8(self.entry, c_uname.as_ptr());
}
Ok(())
}
/// Set the group name
pub fn set_gname(&mut self, gname: &str) -> Result<()> {
let c_gname = CString::new(gname)
.map_err(|_| Error::InvalidArgument("Group name contains null byte".to_string()))?;
unsafe {
libarchive2_sys::archive_entry_set_gname_utf8(self.entry, c_gname.as_ptr());
}
Ok(())
}
/// Set the symlink target
pub fn set_symlink(&mut self, target: &str) -> Result<()> {
let c_target = CString::new(target)
.map_err(|_| Error::InvalidArgument("Symlink target contains null byte".to_string()))?;
unsafe {
libarchive2_sys::archive_entry_set_symlink_utf8(self.entry, c_target.as_ptr());
}
Ok(())
}
/// Set the hardlink target
pub fn set_hardlink(&mut self, target: &str) -> Result<()> {
let c_target = CString::new(target).map_err(|_| {
Error::InvalidArgument("Hardlink target contains null byte".to_string())
})?;
unsafe {
libarchive2_sys::archive_entry_set_hardlink_utf8(self.entry, c_target.as_ptr());
}
Ok(())
}
/// Set the access time
pub fn set_atime(&mut self, time: SystemTime) {
if let Ok(duration) = time.duration_since(SystemTime::UNIX_EPOCH) {
let nsec = duration.subsec_nanos();
unsafe {
#[cfg(all(target_os = "android", any(target_arch = "arm", target_arch = "x86")))]
{
libarchive2_sys::archive_entry_set_atime(
self.entry,
duration.as_secs() as i32,
nsec as i32,
);
}
#[cfg(target_os = "windows")]
{
libarchive2_sys::archive_entry_set_atime(
self.entry,
duration.as_secs() as i64,
nsec as i32,
);
}
#[cfg(not(any(
target_os = "windows",
all(target_os = "android", any(target_arch = "arm", target_arch = "x86"))
)))]
{
libarchive2_sys::archive_entry_set_atime(
self.entry,
duration.as_secs() as i64,
nsec as i64,
);
}
}
}
}
/// Set the creation time (birth time)
pub fn set_birthtime(&mut self, time: SystemTime) {
if let Ok(duration) = time.duration_since(SystemTime::UNIX_EPOCH) {
let nsec = duration.subsec_nanos();
unsafe {
#[cfg(all(target_os = "android", any(target_arch = "arm", target_arch = "x86")))]
{
libarchive2_sys::archive_entry_set_birthtime(
self.entry,
duration.as_secs() as i32,
nsec as i32,
);
}
#[cfg(target_os = "windows")]
{
libarchive2_sys::archive_entry_set_birthtime(
self.entry,
duration.as_secs() as i64,
nsec as i32,
);
}
#[cfg(not(any(
target_os = "windows",
all(target_os = "android", any(target_arch = "arm", target_arch = "x86"))
)))]
{
libarchive2_sys::archive_entry_set_birthtime(
self.entry,
duration.as_secs() as i64,
nsec as i64,
);
}
}
}
}
/// Set the status change time
pub fn set_ctime(&mut self, time: SystemTime) {
if let Ok(duration) = time.duration_since(SystemTime::UNIX_EPOCH) {
let nsec = duration.subsec_nanos();
unsafe {
#[cfg(all(target_os = "android", any(target_arch = "arm", target_arch = "x86")))]
{
libarchive2_sys::archive_entry_set_ctime(
self.entry,
duration.as_secs() as i32,
nsec as i32,
);
}
#[cfg(target_os = "windows")]
{
libarchive2_sys::archive_entry_set_ctime(
self.entry,
duration.as_secs() as i64,
nsec as i32,
);
}
#[cfg(not(any(
target_os = "windows",
all(target_os = "android", any(target_arch = "arm", target_arch = "x86"))
)))]
{
libarchive2_sys::archive_entry_set_ctime(
self.entry,
duration.as_secs() as i64,
nsec as i64,
);
}
}
}
}
/// Set the device number
pub fn set_dev(&mut self, dev: u64) {
unsafe {
libarchive2_sys::archive_entry_set_dev(self.entry, dev as _);
}
}
/// Set the device major number
pub fn set_devmajor(&mut self, major: u64) {
unsafe {
libarchive2_sys::archive_entry_set_devmajor(self.entry, major as _);
}
}
/// Set the device minor number
pub fn set_devminor(&mut self, minor: u64) {
unsafe {
libarchive2_sys::archive_entry_set_devminor(self.entry, minor as _);
}
}
/// Set the inode number
pub fn set_ino(&mut self, ino: u64) {
unsafe {
libarchive2_sys::archive_entry_set_ino64(self.entry, ino as i64);
}
}
/// Set the number of hard links
pub fn set_nlink(&mut self, nlink: u32) {
unsafe {
libarchive2_sys::archive_entry_set_nlink(self.entry, nlink);
}
}
/// Set the device ID
pub fn set_rdev(&mut self, rdev: u64) {
unsafe {
libarchive2_sys::archive_entry_set_rdev(self.entry, rdev as _);
}
}
/// Set the major device number
pub fn set_rdevmajor(&mut self, major: u64) {
unsafe {
libarchive2_sys::archive_entry_set_rdevmajor(self.entry, major as _);
}
}
/// Set the minor device number
pub fn set_rdevminor(&mut self, minor: u64) {
unsafe {
libarchive2_sys::archive_entry_set_rdevminor(self.entry, minor as _);
}
}
/// Set file flags (BSD-style)
pub fn set_fflags(&mut self, set: u64, clear: u64) {
unsafe {
libarchive2_sys::archive_entry_set_fflags(
self.entry,
set as std::os::raw::c_ulong,
clear as std::os::raw::c_ulong,
);
}
}
/// Get an immutable view of this entry
pub fn as_entry(&self) -> Entry<'_> {
Entry {
entry: self.entry,
_marker: std::marker::PhantomData,
}
}
}
impl Default for EntryMut {
fn default() -> Self {
Self::new()
}
}
impl Drop for EntryMut {
fn drop(&mut self) {
if self.owned && !self.entry.is_null() {
unsafe {
libarchive2_sys::archive_entry_free(self.entry);
}
}
}
}