File tree Expand file tree Collapse file tree
modules/axfs/src/highlevel Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -219,16 +219,13 @@ impl OpenOptions {
219219 }
220220
221221 pub fn open_loc ( & self , loc : Location ) -> VfsResult < OpenResult > {
222- if !self . is_valid ( ) {
223- return Err ( VfsError :: InvalidInput ) ;
224- }
222+ self . check_options ( ) ?;
223+
225224 self . _open ( loc)
226225 }
227226
228227 pub fn open ( & self , context : & FsContext , path : impl AsRef < Path > ) -> VfsResult < OpenResult > {
229- if !self . is_valid ( ) {
230- return Err ( VfsError :: InvalidInput ) ;
231- }
228+ self . check_options ( ) ?;
232229
233230 let loc = match context. resolve_parent ( path. as_ref ( ) ) {
234231 Ok ( ( parent, name) ) => {
@@ -273,24 +270,14 @@ impl OpenOptions {
273270 } )
274271 }
275272
276- pub ( crate ) fn is_valid ( & self ) -> bool {
273+ pub ( crate ) fn check_options ( & self ) -> VfsResult < ( ) > {
277274 if !self . read && !self . write && !self . append {
278- return true ;
275+ return Err ( VfsError :: InvalidInput ) ;
279276 }
280- match ( self . write , self . append ) {
281- ( true , false ) => { }
282- ( false , false ) => {
283- if self . truncate || self . create || self . create_new {
284- return false ;
285- }
286- }
287- ( _, true ) => {
288- if self . truncate && !self . create_new {
289- return false ;
290- }
291- }
277+ if self . create_new && !self . create {
278+ return Err ( VfsError :: AlreadyExists ) ;
292279 }
293- true
280+ Ok ( ( ) )
294281 }
295282}
296283
You can’t perform that action at this time.
0 commit comments