rambo 1 month ago
parent
commit
4d1fbe8da0
1 changed files with 11 additions and 1 deletions
  1. 11 1
      python/sockets/message_handler.py

+ 11 - 1
python/sockets/message_handler.py

@@ -62,6 +62,11 @@ def handlerFolderDelete(limit_path, goods_art_no_arrays, is_write_txt_log):
     for goods_art_revice in goods_art_no_arrays:
         cutout_goods = f"{limit_path}/{goods_art_revice}"
         if os.path.exists(cutout_goods):
+            for root, dirs, files in os.walk(cutout_goods):
+                for file in files:
+                    filepath = os.path.join(root, file)
+                    os.chmod(filepath, stat.S_IWRITE)
+            logger.info(f"解除占用并开始删除目录:{cutout_goods}")
             # 尝试多次删除,增加成功率
             retry_count = 3
             while retry_count > 0:
@@ -69,7 +74,10 @@ def handlerFolderDelete(limit_path, goods_art_no_arrays, is_write_txt_log):
                     shutil.rmtree(cutout_goods, onerror=settings.handle_remove_readonly)
                     del move_folder_array[goods_art_revice]
                     break
-                except PermissionError as e:
+                except OSError as e:
+                    logger.info(f"目录已经被删除-OSError:{str(e)}")
+                    break
+                except (PermissionError) as e:
                     retry_count -= 1
                     if retry_count == 0:
                         logger.info(f"抠图前目录删除出现问题-PermissionError:{str(e)};{goods_art_revice};{cutout_goods}")
@@ -84,6 +92,7 @@ def handlerFolderDelete(limit_path, goods_art_no_arrays, is_write_txt_log):
                         else:
                             raise UnicornException(f"目录检查出现问题:{str(e)},请关闭错误提示中的被占用文件")
                     else:
+                        logger.info(f"抠图前目录删除出现问题--PermissionError:{str(e)};{retry_count}")
                         time.sleep(0.5)  # 等待0.5秒后重试
                 except Exception as e:
                     retry_count -= 1
@@ -99,6 +108,7 @@ def handlerFolderDelete(limit_path, goods_art_no_arrays, is_write_txt_log):
                         else:
                             raise UnicornException(f"目录检查出现问题:{str(e)},请关闭错误提示中的被占用文件")
                     else:
+                        logger.info(f"抠图前目录删除出现问题--Exception:{str(e)};{retry_count}")
                         time.sleep(0.5)  # 等待0.5秒后重试
     
     return move_folder_array