@@ -34,19 +34,19 @@ impl OverlayFS {
34
34
if path. is_empty ( ) {
35
35
return Ok ( self . layers [ 0 ] . clone ( ) ) ;
36
36
}
37
- if self . whiteout_path ( path) ?. exists ( ) {
37
+ if self . whiteout_path ( path) ?. exists ( ) ? {
38
38
return Err ( VfsError :: FileNotFound {
39
39
path : path. to_string ( ) ,
40
40
} ) ;
41
41
}
42
42
for layer in & self . layers {
43
43
let layer_path = layer. join ( & path[ 1 ..] ) ?;
44
- if layer_path. exists ( ) {
44
+ if layer_path. exists ( ) ? {
45
45
return Ok ( layer_path) ;
46
46
}
47
47
}
48
48
let read_path = self . write_layer ( ) . join ( & path[ 1 ..] ) ?;
49
- if !read_path. exists ( ) {
49
+ if !read_path. exists ( ) ? {
50
50
return Err ( VfsError :: FileNotFound {
51
51
path : path. to_string ( ) ,
52
52
} ) ;
@@ -73,7 +73,7 @@ impl OverlayFS {
73
73
let separator = path. rfind ( '/' ) ;
74
74
if let Some ( index) = separator {
75
75
let parent_path = & path[ ..index] ;
76
- if self . exists ( parent_path) {
76
+ if self . exists ( parent_path) ? {
77
77
self . write_path ( parent_path) ?. create_dir_all ( ) ?;
78
78
return Ok ( ( ) ) ;
79
79
}
@@ -87,23 +87,23 @@ impl OverlayFS {
87
87
impl FileSystem for OverlayFS {
88
88
fn read_dir ( & self , path : & str ) -> VfsResult < Box < dyn Iterator < Item = String > > > {
89
89
let actual_path = if !path. is_empty ( ) { & path[ 1 ..] } else { path } ;
90
- if !self . read_path ( path) ?. exists ( ) {
90
+ if !self . read_path ( path) ?. exists ( ) ? {
91
91
return Err ( VfsError :: FileNotFound {
92
92
path : path. to_string ( ) ,
93
93
} ) ;
94
94
}
95
95
let mut entries = HashSet :: < String > :: new ( ) ;
96
96
for layer in & self . layers {
97
97
let layer_path = layer. join ( actual_path) ?;
98
- if layer_path. exists ( ) {
98
+ if layer_path. exists ( ) ? {
99
99
for path in layer_path. read_dir ( ) ? {
100
100
entries. insert ( path. filename ( ) ) ;
101
101
}
102
102
}
103
103
}
104
104
// remove whiteout entries that have been removed
105
105
let whiteout_path = self . write_layer ( ) . join ( & format ! ( ".whiteout{}" , path) ) ?;
106
- if whiteout_path. exists ( ) {
106
+ if whiteout_path. exists ( ) ? {
107
107
for path in whiteout_path. read_dir ( ) ? {
108
108
let filename = path. filename ( ) ;
109
109
if filename. ends_with ( "_wo" ) {
@@ -118,7 +118,7 @@ impl FileSystem for OverlayFS {
118
118
self . ensure_has_parent ( path) ?;
119
119
self . write_path ( path) ?. create_dir ( ) ?;
120
120
let whiteout_path = self . whiteout_path ( path) ?;
121
- if whiteout_path. exists ( ) {
121
+ if whiteout_path. exists ( ) ? {
122
122
whiteout_path. remove_file ( ) ?;
123
123
}
124
124
Ok ( ( ) )
@@ -132,15 +132,15 @@ impl FileSystem for OverlayFS {
132
132
self . ensure_has_parent ( path) ?;
133
133
let result = self . write_path ( path) ?. create_file ( ) ?;
134
134
let whiteout_path = self . whiteout_path ( path) ?;
135
- if whiteout_path. exists ( ) {
135
+ if whiteout_path. exists ( ) ? {
136
136
whiteout_path. remove_file ( ) ?;
137
137
}
138
138
Ok ( result)
139
139
}
140
140
141
141
fn append_file ( & self , path : & str ) -> VfsResult < Box < dyn Write > > {
142
142
let write_path = self . write_path ( path) ?;
143
- if !write_path. exists ( ) {
143
+ if !write_path. exists ( ) ? {
144
144
self . ensure_has_parent ( path) ?;
145
145
self . read_path ( path) ?. copy_file ( & write_path) ?;
146
146
}
@@ -151,20 +151,20 @@ impl FileSystem for OverlayFS {
151
151
self . read_path ( path) ?. metadata ( )
152
152
}
153
153
154
- fn exists ( & self , path : & str ) -> bool {
155
- if self . whiteout_path ( path) . expect ( "whiteout_path" ) . exists ( ) {
156
- return false ;
154
+ fn exists ( & self , path : & str ) -> VfsResult < bool > {
155
+ if self . whiteout_path ( path) . expect ( "whiteout_path" ) . exists ( ) ? {
156
+ return Ok ( false ) ;
157
157
}
158
158
self . read_path ( path)
159
159
. map ( |path| path. exists ( ) )
160
- . unwrap_or ( false )
160
+ . unwrap_or ( Ok ( false ) )
161
161
}
162
162
163
163
fn remove_file ( & self , path : & str ) -> VfsResult < ( ) > {
164
164
// Ensure path exists
165
165
self . read_path ( path) ?;
166
166
let write_path = self . write_path ( path) ?;
167
- if write_path. exists ( ) {
167
+ if write_path. exists ( ) ? {
168
168
write_path. remove_file ( ) ?;
169
169
}
170
170
let whiteout_path = self . whiteout_path ( path) ?;
@@ -177,7 +177,7 @@ impl FileSystem for OverlayFS {
177
177
// Ensure path exists
178
178
self . read_path ( path) ?;
179
179
let write_path = self . write_path ( path) ?;
180
- if write_path. exists ( ) {
180
+ if write_path. exists ( ) ? {
181
181
write_path. remove_dir ( ) ?;
182
182
}
183
183
let whiteout_path = self . whiteout_path ( path) ?;
@@ -218,7 +218,7 @@ mod tests {
218
218
lower_path. remove_file ( ) ?;
219
219
assert_eq ! ( & overlay_path. read_to_string( ) ?, "Hello Upper" ) ;
220
220
upper_path. remove_file ( ) ?;
221
- assert ! ( !overlay_path. exists( ) , "File should not exist anymore" ) ;
221
+ assert ! ( !overlay_path. exists( ) ? , "File should not exist anymore" ) ;
222
222
Ok ( ( ) )
223
223
}
224
224
@@ -254,19 +254,19 @@ mod tests {
254
254
fn create_dir ( ) -> VfsResult < ( ) > {
255
255
let ( lower_root, _upper_root, overlay_root) = create_roots ( ) ;
256
256
lower_root. join ( "foo" ) ?. create_dir_all ( ) ?;
257
- assert ! ( overlay_root. join( "foo" ) ?. exists( ) , "dir should exist" ) ;
257
+ assert ! ( overlay_root. join( "foo" ) ?. exists( ) ? , "dir should exist" ) ;
258
258
overlay_root. join ( "foo/bar" ) ?. create_dir ( ) ?;
259
- assert ! ( overlay_root. join( "foo/bar" ) ?. exists( ) , "dir should exist" ) ;
259
+ assert ! ( overlay_root. join( "foo/bar" ) ?. exists( ) ? , "dir should exist" ) ;
260
260
Ok ( ( ) )
261
261
}
262
262
263
263
#[ test]
264
264
fn create_file ( ) -> VfsResult < ( ) > {
265
265
let ( lower_root, _upper_root, overlay_root) = create_roots ( ) ;
266
266
lower_root. join ( "foo" ) ?. create_dir_all ( ) ?;
267
- assert ! ( overlay_root. join( "foo" ) ?. exists( ) , "dir should exist" ) ;
267
+ assert ! ( overlay_root. join( "foo" ) ?. exists( ) ? , "dir should exist" ) ;
268
268
overlay_root. join ( "foo/bar" ) ?. create_file ( ) ?;
269
- assert ! ( overlay_root. join( "foo/bar" ) ?. exists( ) , "file should exist" ) ;
269
+ assert ! ( overlay_root. join( "foo/bar" ) ?. exists( ) ? , "file should exist" ) ;
270
270
Ok ( ( ) )
271
271
}
272
272
@@ -298,13 +298,13 @@ mod tests {
298
298
. create_file ( ) ?
299
299
. write_all ( b"Hello Lower\n " ) ?;
300
300
assert ! (
301
- overlay_root. join( "foo/bar.txt" ) ?. exists( ) ,
301
+ overlay_root. join( "foo/bar.txt" ) ?. exists( ) ? ,
302
302
"file should exist"
303
303
) ;
304
304
305
305
overlay_root. join ( "foo/bar.txt" ) ?. remove_file ( ) ?;
306
306
assert ! (
307
- !overlay_root. join( "foo/bar.txt" ) ?. exists( ) ,
307
+ !overlay_root. join( "foo/bar.txt" ) ?. exists( ) ? ,
308
308
"file should not exist anymore"
309
309
) ;
310
310
@@ -313,7 +313,7 @@ mod tests {
313
313
. create_file ( ) ?
314
314
. write_all ( b"Hello Overlay\n " ) ?;
315
315
assert ! (
316
- overlay_root. join( "foo/bar.txt" ) ?. exists( ) ,
316
+ overlay_root. join( "foo/bar.txt" ) ?. exists( ) ? ,
317
317
"file should exist"
318
318
) ;
319
319
assert_eq ! (
@@ -328,16 +328,16 @@ mod tests {
328
328
let ( lower_root, _upper_root, overlay_root) = create_roots ( ) ;
329
329
lower_root. join ( "foo" ) ?. create_dir_all ( ) ?;
330
330
lower_root. join ( "foo/bar" ) ?. create_dir_all ( ) ?;
331
- assert ! ( overlay_root. join( "foo/bar" ) ?. exists( ) , "dir should exist" ) ;
331
+ assert ! ( overlay_root. join( "foo/bar" ) ?. exists( ) ? , "dir should exist" ) ;
332
332
333
333
overlay_root. join ( "foo/bar" ) ?. remove_dir ( ) ?;
334
334
assert ! (
335
- !overlay_root. join( "foo/bar" ) ?. exists( ) ,
335
+ !overlay_root. join( "foo/bar" ) ?. exists( ) ? ,
336
336
"dir should not exist anymore"
337
337
) ;
338
338
339
339
overlay_root. join ( "foo/bar" ) ?. create_dir ( ) ?;
340
- assert ! ( overlay_root. join( "foo/bar" ) ?. exists( ) , "dir should exist" ) ;
340
+ assert ! ( overlay_root. join( "foo/bar" ) ?. exists( ) ? , "dir should exist" ) ;
341
341
Ok ( ( ) )
342
342
}
343
343
0 commit comments