Empty Folders Left Behind - Ignore Pattern Issue?

Hello:

I’m seeing a minor issue arising from some Ignore Patterns - but I don’t know if it stems from my Ignore Pattern formatting, or something else.

I have a shared folder which gets a new subfolder added each day, and then a standard set of subfolders inside that - e.g.

2022.07.01
    - IN
    - OUT
2022.07.02
    - IN
    - OUT
2022.07.03
    - IN
    - OUT
etc

Every day, a new folder gets added, and the folder from a month previously gets deleted. All good so far - this works as expected amongst most of our systems.

However, one of our devices only needs the OUT folders syncing to it - so we have the following set up in Ignore Patterns (below a standard set of OS ignores, which don’t cause a problem in any other situation):

!/*/OUT
**

This works as expected - apart from in respect of the older folders getting deleted: although the OUT folder gets deleted, the folder above it remains - e.g.

2022.07.01
    <Nothing inside here>
2022.07.02
    <Nothing inside here>
2022.07.03
    - OUT
etc

I’ve checked for any hidden files (using ls -lah) which might be preventing the folders from being deleted - but cannot find any. Machines which don’t have the Ignore Pattern shown above don’t suffer from this issue - they get the dated folder deleted as expected.

Any ideas?

Something like this will do the job.

!/*/OUT
/*/
!/

A similar problem was discussed previously in https://forum.syncthing.net/t/adding-the-ignore-condition-only-files-can-be-deleted-but-folders-cannot-be-deleted/18305. The final ignore patterns there ended up being quite convoluted.

1 Like

Hi @tomasz86

Thanks for the guidance. I’ve just tried exactly as you suggested, and unfortunately it hasn’t helped:

  • I applied the Ignore Pattern;
  • On another device, I created a Test folder - with nothing inside it;
  • On this device, the folder synced into place - even though nothing was inside.

I then modified the Ignore Pattern thus:

!/*/OUT
/*
!/
  • Created a new empty test folder - it did not sync into place;
  • Added an OUT subfolder - now the test folder and subfolder did sync into place;
  • Deleted the test folder from another device - now the OUT folder was deleted, but not the parent folder. (i.e. just the same as I’m seeing with the original Ignore Pattern).

I’ve tried looking at the thread you linked, and how you came up with the Ignore Pattern there is beyond me!

I don’t think what you want is possible. You want to ignore top level directories, except if they have an OUT folder inside them. That’s not something you can express in the ignore pattern language. You can potentially sync the top level folders and nothing inside them except OUT;

!/*                // sync top level things
!/*/OUT            // and "OUT" inside them
**                 // but not anything else

untested, from top of mind, etc

Any given thing, like your top level folders, is either ignored or not. If it’s ignored it isn’t created and also isn’t deleted when it’s removed on the other side. The fact that it materializes anyway is because it’s needed for the un-ignored thing under “OUT”. It still won’t be removed when deleted on the other side. For it to be removed when the other side deletes it, it would have to have been created when the other side created it – that is, not ignored to begin with.

1 Like

Thanks @calmh - that all makes perfect sense as you describe it.

I guess that would need an additional feature added - another Ignore Pattern modifier for allow item to be deleted by the sync cluster, even if it’s ignored.

Of course, that’s rather a niche requirement, so I won’t hold my breath! :grin:

1 Like

You’re missing a / in your patterns :wink:. They should be as follows.

!/*/OUT
/*/
!/

or actually even just

!/*/OUT
/*/

The key here is not to ignore the parent folder, which is /* in your case. Of course, this also means that other top-level folders, which don’t contain OUT, will also get synced, but I don’t think anything can be done about it. They will be just empty with nothing inside them though (thanks to ignoring /*/).

2 Likes

Hi @tomasz86:

Thanks for the additional information!

Yes - that’s what I tried after your first post, but I found it was syncing a top-level folder - which I wasn’t expecting at the time…

Having read your explanation since, I see what you’re aiming at - an interesting alternative! I’ll have to think as to which of the two approaches is going to be more appropriate for this machine!

1 Like

Hi @tomasz86:

Just thought I’d pop a thankyou in here for your Ignore Pattern approach; yes, it’s not ideal - but it’s much better than I had before - so thanks!

2 Likes

No problem. Glad I could help :slightly_smiling_face:.