osync icon indicating copy to clipboard operation
osync copied to clipboard

Deleted empty folders do not sync between the initiator and target

Open Julpro21 opened this issue 1 year ago • 9 comments

Empty folders can by sync between the initiator and target. However, when I delete some of them, say, inside the initiator folder, the deletion does not reflect to the target folder. In fact, it breaks the whole synchronization. I got this message:

cp: /Users//Desktop/B/A is a directory (not copied). TIME: 1 - \e[91mCannot move [/Users//Desktop/B/A] to deletion directory [/Users/*/Desktop/B/.osync_workdir/deleted] on target.\e[0m TIME: 1 - \e[1;33;41mDeletion on target replica failed.\e[0m TIME: 1 - \e[91m_ExecTasksPidsCheck called by [Sync_deletionPropagation] finished monitoring pid [6841] with exitcode [1].\e[0m TIME: 1 - \e[91mosync finished with errors.\e[0m

Please note that this behavior disappears and everything works correctly if I set: SOFT_DELETE=false. Also, I'm using a Macbook Pro with Sonoma installed.

Julpro21 avatar Apr 29 '24 10:04 Julpro21

I'd really need a reproducible example, eg folder tree before deletion, folder tree after sync, full error message, osync version. With this, I'm pretty sure that I could make a quick fix.

deajan avatar Apr 29 '24 14:04 deajan

Thank you for your reply. Here is a reproducible example:

Create two folders inside the initiator folder (called initiator_folder). One subfolder is not empty (subfolder_1) and the other one is empty (subfolder_2):

mkdir -p "$HOME/Desktop/initiator_folder/subfolder_1" touch "$HOME/Desktop/initiator_folder/subfolder_1/example.txt" mkdir -p "$HOME/Desktop/initiator_folder/subfolder_2"

Now create the target folder (target_folder):

mkdir -p "$HOME/Desktop/target_folder"

Using osync:

bash osync.sh --initiator="$HOME/Desktop/initiator_folder" --target="$HOME/Desktop/target_folder"

So far so good. But now let's remove the empty subfolder and run osync again. Please note that if we remove the non empty folder, it will work with no errors. The problem is with the empty folders.

rm -rf "$HOME/Desktop/initiator_folder/subfolder_2" bash osync.sh --initiator="$HOME/Desktop/initiator_folder" --target="$HOME/Desktop/target_folder"

The following error message will appear:

cp: /Users/xx/Desktop/target_folder/subfolder_2 is a directory (not copied). TIME: 0 - \e[91mCannot move [/Users/xx/Desktop/target_folder/subfolder_2] to deletion directory [/Users/xx/Desktop/target_folder/.osync_workdir/deleted] on target.\e[0m TIME: 0 - \e[1;33;41mDeletion on target replica failed.\e[0m TIME: 0 - \e[91m_ExecTasksPidsCheck called by [Sync_deletionPropagation] finished monitoring pid [17506] with exitcode [1].\e[0m TIME: 1 - \e[91mosync finished with errors.\e[0m

I believe that this is mainly because of (rm -f and cp -p) when used with folders. On macOS, you need the "r" option for recursive with folders. So, we should use (rm -rf, and cp -rp or cp -Rp).

Finally, I just saw this similar discussions here: https://github.com/deajan/osync/pull/254

Julpro21 avatar Apr 29 '24 15:04 Julpro21

So you're running osync 1.3-rtm on MacOS which version ?

I'd be thrilled to test your "-r" reasoning, but I dont have any macs :( Mind to mod osync.sh with your suggestion and report back ? I'll happily make a release.

deajan avatar Apr 29 '24 15:04 deajan

I'm running osync-1.3 with macOS Sonoma (14.4.1).

Julpro21 avatar Apr 29 '24 15:04 Julpro21

I did the following and it works perfectly now: sed -i '' 's/cp -p/cp -pR/g' "./osync.sh" sed -i '' 's/rm -f/rm -rf/g' "./osync.sh"

Julpro21 avatar Apr 29 '24 15:04 Julpro21

Please have a look at: https://github.com/deajan/osync/pull/254

Julpro21 avatar Apr 29 '24 15:04 Julpro21

That's a bit broad ;) I'll see whether those changes will work with the unit tests. If so, I'll make a release. You may make a PR (on n_osync.sh) if you wish to be mentionned.

Thank you for your diag ;)

deajan avatar Apr 29 '24 15:04 deajan

Thank you for your help. I'm not sure if I should mention this here, but the following typos are in the osync.sh file.

"# Leave the possibity to set SLEEP_TIME as environment variable when runinng with bash -x in order to avoid spamming console"

possibity should be possibility runinng should be running

Thanks again

Julpro21 avatar Apr 29 '24 15:04 Julpro21

Sure. I'll have them sorted. Thanks.

deajan avatar Apr 29 '24 16:04 deajan

Longest ping for this to be resolved ;) Sorry

deajan avatar Sep 04 '24 13:09 deajan