Skip to content

Commit 9c8cb61

Browse files
committed
fix(license): eNOENT when writing missing LICENSE.md
1 parent e36ba4b commit 9c8cb61

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

fs-stage/commit.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,25 @@ async function openDirectory(options: OpenOptions<Directory>): Promise<OpenDirec
9595

9696
async 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

110119
async function write(stage: OpenFsStage): Promise<void> {

0 commit comments

Comments
 (0)