Skip to content

Commit 3575981

Browse files
committed
fix: exdev error workaround #856
1 parent 81c880b commit 3575981

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/lib/datasource/Local.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createReadStream, existsSync } from 'fs';
2-
import { access, constants, readdir, rename, rm, stat, writeFile } from 'fs/promises';
2+
import { access, constants, copyFile, readdir, rename, rm, stat, writeFile } from 'fs/promises';
33
import { join } from 'path';
44
import { Readable } from 'stream';
55
import { Datasource } from './Datasource';
@@ -40,7 +40,18 @@ export class LocalDatasource extends Datasource {
4040
"Something went very wrong! the temporary directory wasn't readable or the file doesn't exist.",
4141
);
4242

43-
return rename(data, path);
43+
try {
44+
await rename(data, path);
45+
} catch (err) {
46+
// docker may throw exdev errors when renaming across volumes (/tmp to something else)
47+
if ((err as NodeJS.ErrnoException).code === 'EXDEV') {
48+
await copyFile(data, path);
49+
await rm(data);
50+
return;
51+
} else {
52+
throw err;
53+
}
54+
}
4455
}
4556

4657
return writeFile(path, data);

0 commit comments

Comments
 (0)