Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore everything in a directory except one subfolder

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/*^/
like image 822
det Avatar asked Jul 08 '16 13:07

det


2 Answers

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.

like image 166
Will Barnwell Avatar answered Nov 29 '22 20:11

Will Barnwell


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.

like image 21
gusbrs Avatar answered Nov 29 '22 22:11

gusbrs