Skip to content

Commit 655102f

Browse files
@jotadevelopersergiohgz
authored andcommitted
fix: remove temp file whether is emtpy and fails
1 parent 20bf5f7 commit 655102f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

plugins/local-storage/src/local-fs.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class LocalFS implements ILocalPackageManager {
179179

180180
const temporalName = path.join(this.path, `${name}.tmp-${String(Math.random()).replace(/^0\./, '')}`);
181181
const file = fs.createWriteStream(temporalName);
182+
const removeTempFile = () => fs.unlink(temporalName, function() {});
182183
let opened = false;
183184
uploadStream.pipe(file);
184185

@@ -201,15 +202,20 @@ class LocalFS implements ILocalPackageManager {
201202
uploadStream.on('end', onend);
202203
}
203204
};
205+
204206
uploadStream.abort = function() {
205207
if (opened) {
206208
opened = false;
207209
file.on('close', function() {
208-
fs.unlink(temporalName, function() {});
210+
removeTempFile();
209211
});
212+
} else {
213+
// if the file does not recieve any byte never is opened and has to be removed anyway.
214+
removeTempFile();
210215
}
211216
file.end();
212217
};
218+
213219
file.on('open', function() {
214220
opened = true;
215221
// re-emitting open because it's handled in storage.js

0 commit comments

Comments
 (0)