PortableApps / Toucan

sync, backup and secure, all in one place
http://portableapps.com/apps/utilities/toucan
GNU General Public License v2.0
126 stars 23 forks source link

Sync (mirror) doesn't delete destination recursive #22

Closed FiSHYsolutions closed 5 years ago

FiSHYsolutions commented 6 years ago

I try to use sync (mirror) but it doesn't work as expected.

Summary from help: "Mirror -> Copy every file in the source directory to the destination directory, and delete every file in the destination directory that is not in the source directory."

Ok, let's go. We have a testfolder "Source" with some content and an empty folder "Destination". At first we mirror-sync from source to destination:

1 1_log

Everything looks fine. Now i delete "Folder A" from source (using Windows Explorer), hit refresh in Toucan and it shows the source as it is (without "Folder A").

2

So far so good, i hit the "Run"-Button to mirror-sync again from source to destination and i expect the complete removal of "Folder A" (and it's content) in destination.

2_log

And here something went wrong. At first: the log shows "Removed ... file a.txt" twice. Why? There was only one file. The log also says "Folder A.1" and "Folder A" were removed, but after refreshing Toucan we find the subdirectory untouched (and we can also access it with Explorer or something else). So they are not deleted:

3

alex-ter commented 5 years ago

So the duplicate "Removed file" entries are due to the duplicated logging in the code (here and here).

The non-removal of the directory is most probably because of the fact that the files inside it are not removed - apparently the code uses a directory deletion function that doesn't remove non-empty dirs and looks like the error handling there is incorrect (here)

Now why the file is not actually removed is hard to say based on the information I have - the code looks okay (except that apparently the error handling is also not doing the job properly - the file is not removed, but it thinks it is). Could you please check if the file in question is by chance set as read-only? If so, please try setting the "Ignore Read-Only" option under "Other" - I see you have it unchecked. Or if that doesn't work - remove the read-only flag in the Windows Explorer directly.

FiSHYsolutions commented 5 years ago

nope, the file is not flagged "read only". it's a very simple txt-file, created seconds before the test i did to report this behaviour and IMHO it should be very easy to re-enact it. i never did any special shit. it's an absolute plain usage of toucan's sync and the described problem appears with every directories i try to re-sync. target-data is not deleted recursive.

alex-ter commented 5 years ago

Ok, thanks for information. Let me see if I can reproduce this.

alex-ter commented 5 years ago

Ok, I can't seem to reproduce this. I've however done some error handling cleanup, fixed the duplicate logging for file removal and used a different function for dir removal (wxRmdir() vs current wxRmDir()), which I think was a typo in the first place. The Toucan binary with the new approach is attached - could you please try it out, using exactly the same scenario you used orignally, and report back? If not fixing it, it should at least be properly reporting deletion statuses, which should help us move forward with investigation.

To make it easier to test - just temporarily replace your current Toucan binary. As there are no other changes, this file is fully compatible with your current rules/variables/jobs files. However it's always wise to create a backup copy of your full Portableapps setup just in case.

Specifically:

  1. Rename <your portableapps install dir>\PortableApps\Toucan\App\Toucan\toucan.exe to toucan.exe.orig
  2. Unpack the attached zip and copy toucan.exe into the same dir
  3. Run Toucan and execute the scenario

toucan.zip

FiSHYsolutions commented 5 years ago

Issue isn't solved.

Toucan_v3 1 6_failed

The log starts with an error which is true (but i didn't understand the missing backslash between "Folder A.1" and "file a.1.txt", maybe that's the issue?). But "Folder A\file a.txt" were deleted successfully!

alex-ter commented 5 years ago

Okay, as they say: "better late than never", right? :smiley:

I was finally able to find the time to look at this further, found the root cause, reproduced and fixed it. The reason was that with nested dirs the recursive call to dir deletion subroutine passed the path as a file (not dir) name, which caused that result you observed with lack of the path separator. That caused the file deletion to fail inside the dir, so the dir deletion failed as well.

I'm pretty sure it's fixed now as I can no longer reproduce it (after having the same result as you with the original code), but just to make sure - here's the test build, if you're still up to that, could you please check it out according to the instructions from my earlier comment and tell me if it fixes it for you?

toucan.zip

FiSHYsolutions commented 5 years ago

Problem solved! I used a new fresh toucan v3.1.5 (from PortableApps), replaced App\Toucan\toucan.exe, and everything works as expected. Tried it with Windows 7 Build 7601 SP1 x64 and Windows 10 Pro x64 Version 1809 (the Toucan-log said "NT 6.2 build 9200", thats maybe incorrect?).

Thank you very much!

alex-ter commented 5 years ago

Great, thank you for confirmation. I'll prepare a release hopefully some time this week.