Ignore everything in a directory except one subfolder
Asked Answered
L

3

8

I have a directory ~/x7/music/sfx.
There are some files and folders in the root of ~/x7/music.
I need to sync only the sfx folder and ignore anything else in music.

I've tried many variants, but all of them was wrong.

ignore = Name music/*
ignorenot = Regex music/sfx/.* (OR just *)

does not work.

I was expecting to use something like

ignore = Name music/*^/
Lesko answered 8/7, 2016 at 13:45 Comment(0)
C
1

I'm not familiar with unison, but to ignore everything except sfx you could use

ignore = Regex /root/path/to/music/.*
ignorenot Regex /root/path/to/music/sfx/.*

Documentation Source

There is also an ignorenot preference, which specifies a set of patterns for paths that should not be ignored, even if they match an ignore pattern. However, the interaction of these two sets of patterns can be a little tricky. Here is exactly how it works:

  • Unison starts detecting updates from the root of the replicas—i.e., from the empty path. If the empty path matches an ignore pattern and does not match an ignorenot pattern, then the whole replica will be ignored. (For this reason, it is not a good idea to include Name * as an ignore pattern. If you want to ignore everything except a certain set of files, use Name ?*.)

  • If the root is a directory, Unison continues looking for updates in all the immediate children of the root. Again, if the name of some child matches an ignore pattern and does not match an ignorenot pattern, then this whole path including everything below it will be ignored.

  • If any of the non-ignored children are directories, then the process continues recursively.

Concinnate answered 8/7, 2016 at 17:21 Comment(4)
unfortunately, your solution is not working properly. It still syncing all music folder. I cannot sync only this folder, because unison support 2 sources (in example remote and local) so i can use only regex for this specific operation.Lesko
i looked at their docs, where they explain how to do this, and updated my answerConcinnate
Thank you for trying to help) This string: ignore = Regex /home/det/x7/music/((?!sfx).)* or (~./x7/music...) tells error: Fatal error: File "x7", line 33: Malformed pattern "Regex /home/det/x7/music/((?!sfx).)*".Lesko
Updated to use ignorenotConcinnate
G
1

Following unison's documentation, if a certain path is ignored then so does everything bellow it. So, if you want to ignore everything within a folder except a subfolder, you should not ignore the folder itself, but everything inside it (which is different), and then use ignorenot.

ignore = Path x7/music/?*
ignore = Path x7/music/.?*
ignorenot = Path x7/music/sfx

That should do it.

Regarding the particular regexs used there, I'm following once again unison's documentation advice: "For this reason, it is not a good idea to include Name * as an ignore pattern. If you want to ignore everything except a certain set of files, use Name ?*." The second ignore line ignores also hidden files/folders within music, if that's necessary for you.

Gonna answered 23/7, 2017 at 0:26 Comment(0)
S
0

On 2.48.3, this should work:

ignore = Path /root/path/to/music/*
ignorenot = Path /root/path/to/music/sfx
Superconductivity answered 19/2, 2020 at 7:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.