@@ -1147,6 +1147,9 @@ BOOL FastCopy::ReadProc(int dir_len, BOOL confirm_dir)
11471147 ret = DeleteFileProc (confirmDst, confirm_len, dstStat->cFileName , dstStat);
11481148 }
11491149 else {
1150+ #if 4032
1151+ DebugW (L" Delete req %s\n " ,dstStat->cFileName );
1152+ #endif
11501153 SendRequest (DELETE_FILES, 0 , dstStat);
11511154 }
11521155 if (isAbort)
@@ -2350,6 +2353,86 @@ BOOL FastCopy::DeleteDirProc(void *path, int dir_len, void *fname, FileStat *sta
23502353 return ret;
23512354}
23522355
2356+ #if 4032
2357+ BOOL IsFileExists (void * path)
2358+ {
2359+ HANDLE fh;
2360+
2361+ if ((fh = CreateFileV (path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, 0 ,
2362+ OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS , 0 )) == INVALID_HANDLE_VALUE) {
2363+ return FALSE ;
2364+ }
2365+
2366+ ::CloseHandle (fh);
2367+ return TRUE ;
2368+ }
2369+
2370+ BOOL CreateParentDirectory (void *path, int dirBaseLen)
2371+ {
2372+ WCHAR * dir = new WCHAR [MAX_PATH_EX];
2373+ int i, len;
2374+
2375+ strcpyV ( dir, path);
2376+ len = strlenV (dir);
2377+
2378+ len --;
2379+ for ( i= dirBaseLen-1 ; i< len ; i++) {
2380+ if ( GetChar (dir,i) == ' \\ ' ) {
2381+ SetChar (dir,i,' \0 ' );
2382+ // Debug("Create dir %s\n",dir);
2383+ if ( !CreateDirectoryV (dir,NULL ) ) {
2384+ int err = ::GetLastError ();
2385+ if ( err != ERROR_ALREADY_EXISTS ) {
2386+ DebugW (L" err = %x\n " , err);
2387+ }
2388+ }
2389+ SetChar (dir,i,' \\ ' );
2390+ }
2391+ }
2392+
2393+ delete dir;
2394+ return TRUE ;
2395+ }
2396+
2397+
2398+ BOOL FastCopy::MoveFileToArchive (void *path)
2399+ {
2400+ if ( IsFileExists (path) ) {
2401+ WCHAR * archivePath = new WCHAR [MAX_PATH_EX];
2402+ int archive_len = strlenV (ARCHIVE_V);
2403+
2404+ // DebugW(L"MoveFileToArchive path=%s\n",path);
2405+
2406+ memcpy (archivePath, path, dstBaseLen * CHAR_LEN_V);
2407+ strcpyV (MakeAddr (archivePath, dstBaseLen -1 ),ARCHIVE_V);
2408+ strcpyV (MakeAddr (archivePath, dstBaseLen -1 + archive_len ),MakeAddr (path, dstBaseLen));
2409+ DebugW (L" archive path=%s\n " ,archivePath);
2410+
2411+ // delete old archive file
2412+ if (DeleteFileV (archivePath) == FALSE ) {
2413+ int err = ::GetLastError ();
2414+ if ( err == ERROR_PATH_NOT_FOUND ) {
2415+ CreateParentDirectory (archivePath, dstBaseLen -1 + archive_len);
2416+ }
2417+ else if (err != ERROR_FILE_NOT_FOUND) {
2418+ DebugW (L" del err = %x\n " , err);
2419+ }
2420+ }
2421+
2422+ if (MoveFileV (path,archivePath) == FALSE ) {
2423+ int err = ::GetLastError ();
2424+ if ( err != ERROR_FILE_NOT_FOUND ) {
2425+ DebugW (L" move err = %x\n " , err);
2426+ }
2427+ }
2428+
2429+ delete archivePath;
2430+ }
2431+ return TRUE ;
2432+ }
2433+
2434+ #endif /* 4032 */
2435+
23532436BOOL FastCopy::DeleteFileProc (void *path, int dir_len, void *fname, FileStat *stat)
23542437{
23552438 int len = sprintfV (MakeAddr (path, dir_len), FMT_STR_V, fname);
@@ -2359,6 +2442,14 @@ BOOL FastCopy::DeleteFileProc(void *path, int dir_len, void *fname, FileStat *st
23592442 if (stat->dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
23602443 SetFileAttributesV (path, FILE_ATTRIBUTE_NORMAL);
23612444 }
2445+ #if 4032
2446+ if ( info.mode == SYNCCP_MODE && (info.flags & SYNC_DEL_TO_ARCHIVE)) {
2447+ DebugW (L" DeleteFileProc %s\n " ,(char *)path);
2448+ MoveFileToArchive (path);
2449+ }
2450+ else
2451+ {
2452+ #endif
23622453 void *target = path;
23632454
23642455 if (info.mode == DELETE_MODE && (info.flags & (OVERWRITE_DELETE|OVERWRITE_DELETE_NSA))
@@ -2379,6 +2470,9 @@ BOOL FastCopy::DeleteFileProc(void *path, int dir_len, void *fname, FileStat *st
23792470 total.errFiles ++;
23802471 return ConfirmErr (" DeleteFile" , MakeAddr (target, dstPrefixLen)), FALSE ;
23812472 }
2473+ #if 4032
2474+ }
2475+ #endif
23822476 }
23832477 if (isListing) PutList (MakeAddr (path, dstPrefixLen), PL_DELETE|(is_reparse ? PL_REPARSE : 0 ));
23842478
@@ -3301,6 +3395,12 @@ BOOL FastCopy::WriteFileProc(int dst_len)
33013395
33023396 if (waitTick) Wait ((waitTick + 9 ) / 10 );
33033397
3398+ #if 4032
3399+ if ( info.mode == SYNCCP_MODE && (info.flags & SYNC_DEL_TO_ARCHIVE)) {
3400+ DebugW (L" src = %s,%d \n dst = %s,%d \n " ,(char *)src,srcBaseLen,(char *)dst,dstBaseLen);
3401+ MoveFileToArchive (dst);
3402+ }
3403+ #endif
33043404 if (is_require_del) {
33053405 if (!DeleteFileV (dst) && ::GetLastError () != ERROR_FILE_NOT_FOUND) {
33063406 SetFileAttributesV (dst, FILE_ATTRIBUTE_NORMAL);
0 commit comments