@@ -3,6 +3,7 @@ use crate::Result;
3
3
4
4
use alpm_sys:: * ;
5
5
6
+ use std:: cell:: UnsafeCell ;
6
7
use std:: ffi:: CString ;
7
8
use std:: fmt;
8
9
use std:: mem;
@@ -38,8 +39,9 @@ impl File {
38
39
}
39
40
}
40
41
42
+ // TODO unsound: needs lifetime on handle
41
43
pub struct FileList {
42
- pub ( crate ) inner : alpm_filelist_t ,
44
+ inner : UnsafeCell < alpm_filelist_t > ,
43
45
}
44
46
45
47
impl fmt:: Debug for FileList {
@@ -49,22 +51,28 @@ impl fmt::Debug for FileList {
49
51
}
50
52
51
53
impl FileList {
54
+ pub ( crate ) unsafe fn new ( files : alpm_filelist_t ) -> FileList {
55
+ FileList {
56
+ inner : UnsafeCell :: new ( files) ,
57
+ }
58
+ }
59
+
60
+ pub ( crate ) fn as_ptr ( & self ) -> * mut alpm_filelist_t {
61
+ self . inner . get ( )
62
+ }
63
+
52
64
pub fn files ( & self ) -> & [ File ] {
53
- if self . inner . files . is_null ( ) {
65
+ let files = unsafe { * self . as_ptr ( ) } ;
66
+ if files. files . is_null ( ) {
54
67
unsafe { slice:: from_raw_parts ( mem:: align_of :: < File > ( ) as * const File , 0 ) }
55
68
} else {
56
- unsafe { slice:: from_raw_parts ( self . inner . files as * const File , self . inner . count ) }
69
+ unsafe { slice:: from_raw_parts ( files . files as * const File , files . count ) }
57
70
}
58
71
}
59
72
60
73
pub fn contains < S : Into < Vec < u8 > > > ( & self , path : S ) -> Result < Option < File > > {
61
74
let path = CString :: new ( path) . unwrap ( ) ;
62
- let file = unsafe {
63
- alpm_filelist_contains (
64
- & self . inner as * const alpm_filelist_t as * mut alpm_filelist_t ,
65
- path. as_ptr ( ) ,
66
- )
67
- } ;
75
+ let file = unsafe { alpm_filelist_contains ( self . as_ptr ( ) , path. as_ptr ( ) ) } ;
68
76
69
77
if file. is_null ( ) {
70
78
Ok ( None )
0 commit comments