Skip to content

Commit e50e32c

Browse files
fix(store-ftp): check if file exists before creating
1 parent 1aa437e commit e50e32c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/store-ftp/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ export default class FtpStore {
118118
const readableStream = this.#createReadableStream(content);
119119
const absolutePath = this.#absolutePath(filePath);
120120

121+
// Return if file already exists
122+
const fileExists = await client.exists(absolutePath);
123+
if (fileExists) {
124+
return;
125+
}
126+
121127
// Create directory if doesn’t exist
122128
const directory = path.dirname(absolutePath);
123129
const directoryType = await client.exists(directory);

packages/store-ftp/test/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ describe("store-ftp", () => {
7575
);
7676
});
7777

78+
it("Doesn’t create file if already exists", async () => {
79+
await ftp.createFile("foo.md", "foobar");
80+
81+
assert.equal(await ftp.createFile("foo.md", "foobar"), undefined);
82+
});
83+
7884
it("Throws error creating file", async () => {
7985
await assert.rejects(ftp.createFile(undefined, ""), {
8086
message: `FTP store: The "path" argument must be of type string. Received undefined`,

0 commit comments

Comments
 (0)