lrf 2 سال پیش
والد
کامیت
f3329f73f5
1فایلهای تغییر یافته به همراه3 افزوده شده و 2 حذف شده
  1. 3 2
      app/service/disk.js

+ 3 - 2
app/service/disk.js

@@ -58,13 +58,14 @@ class DiskService extends CrudService {
   async dirDelete(filePath, times) {
     if (fs.existsSync(filePath)) {
       const files = fs.readdirSync(filePath);
+      if (files.length > 0 && !times) throw new BusinessError(ErrorCode.SERVICE_FAULT, '内部有文件/目录,请先清空该目录');
+
       for (const file of files) {
         const curPath = path.resolve(filePath, file);
         const fi = fs.statSync(curPath);
         if (fi.isDirectory()) {
-          throw new BusinessError(ErrorCode.SERVICE_FAULT, '内部有文件/目录,请先清空该目录');
           // recurse
-          // this.dirDelete(curPath);
+          this.dirDelete(curPath);
         } else {
           // delete file
           if (_.get(times, 'start_time') && _.get(times, 'end_time')) {