Browse Source

add if in unlink cache file

yusueketk 7 years ago
parent
commit
85f5528722
1 changed files with 8 additions and 5 deletions
  1. 8 5
      src/server/service/file-uploader/gridfs.js

+ 8 - 5
src/server/service/file-uploader/gridfs.js

@@ -35,11 +35,14 @@ module.exports = function(crowi) {
 
   const clearCache = (fileId) => {
     const cacheFile = createCacheFileName(fileId);
-    fs.unlink(cacheFile, (err) => {
-      if (err) {
-        throw new Error('fail to delete cache file', err);
-      }
-    });
+    const stats = fs.statSync(crowi.cacheDir);
+    if (stats.isFile(`attachment-${fileId}`)) {
+      fs.unlink(cacheFile, (err) => {
+        if (err) {
+          throw new Error('fail to delete cache file', err);
+        }
+      });
+    }
   };
 
   lib.uploadFile = async function(filePath, contentType, fileStream, options) {