File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed
Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -95,16 +95,25 @@ async function openDirectory(options: OpenOptions<Directory>): Promise<OpenDirec
9595
9696async function openFile ( options : OpenOptions < File > ) : Promise < OpenFileResult > {
9797 const flags = options . overwrite ? "r+" : "wx+" ;
98- return fs . open ( options . path , flags ) . then (
99- fileHandle => success ( { type : " open-file" , fileHandle , data : options . node . data } ) ,
100- reason => {
101- if ( reason . code === "EEXIST" ) {
102- return failure ( [ { type : "file-exists" , path : options . path } ] ) ;
98+ return fs
99+ . open ( options . path , flags )
100+ . catch ( async reason => {
101+ if ( reason . code === "ENOENT" && options . overwrite ) {
102+ return fs . open ( options . path , "wx+" ) ;
103103 } else {
104104 throw reason ;
105105 }
106- }
107- ) ;
106+ } )
107+ . then (
108+ fileHandle => success ( { type : "open-file" , fileHandle, data : options . node . data } ) ,
109+ reason => {
110+ if ( reason . code === "EEXIST" ) {
111+ return failure ( [ { type : "file-exists" , path : options . path } ] ) ;
112+ } else {
113+ throw reason ;
114+ }
115+ }
116+ ) ;
108117}
109118
110119async function write ( stage : OpenFsStage ) : Promise < void > {
You can’t perform that action at this time.
0 commit comments