@@ -430,6 +430,19 @@ def listDir(self, path, firstDst, spec, rootPath, isSrc=True):
430430 isPath = 1 )
431431 raise e
432432
433+ def ensurePath (self , path ):
434+ if self .breakFlag :
435+ return
436+ scanInterval = self .job ['scanIntervalT' ]
437+ segs = [s for s in path .split ('/' ) if s ]
438+ cur = '/'
439+ for s in segs :
440+ cur = cur + s + '/'
441+ try :
442+ self .alistClient .fileListApi (cur , 0 , scanInterval , None , cur )
443+ except Exception :
444+ self .alistClient .mkdir (cur , scanInterval )
445+
433446 def syncWithHave (self , srcPath , dstPath , spec , srcRootPath , dstRootPath , firstDst ):
434447 """
435448 扫描并同步-目标目录存在目录(意味着要继续扫描目标目录)
@@ -445,9 +458,12 @@ def syncWithHave(self, srcPath, dstPath, spec, srcRootPath, dstRootPath, firstDs
445458 return
446459 try :
447460 srcFiles = self .listDir (srcPath , firstDst , spec , srcRootPath )
448- dstFiles = self .listDir (dstPath , firstDst , spec , dstRootPath , False )
461+ try :
462+ dstFiles = self .listDir (dstPath , firstDst , spec , dstRootPath , False )
463+ except Exception :
464+ self .syncWithOutHave (srcPath , dstPath , spec , srcRootPath , dstRootPath , firstDst )
465+ return
449466 except Exception :
450- # 已在listDir做出日志打印等操作,此处啥都不用做
451467 return
452468 for key in srcFiles .keys ():
453469 # 如果是文件
@@ -486,7 +502,7 @@ def syncWithOutHave(self, srcPath, dstPath, spec, srcRootPath, dstRootPath, firs
486502 status = 2
487503 errMsg = None
488504 try :
489- self .alistClient . mkdir (dstPath , self . job [ 'scanIntervalT' ] )
505+ self .ensurePath (dstPath )
490506 except Exception as e :
491507 status = 7
492508 errMsg = str (e )
0 commit comments