5

I want to sync the content of all subdirectories of a given root but only a few files in the root itself. To do so I would like to ignore all files using the ignore directive (keeping all subdirectories) and re-adding the few files I want to keep with the ignorenot directive. To do so I tried the following two things:

  1. Adding a regex to exclude any entry in the root that contains a slash by adding ignore = Regex ^(?!.*\/).*$ to my profile. But this results in an error message as follows with no further explanation:

    Malformed pattern "Regex ^(?!.*\/).*$"." 
    
  2. First ignoring everything with ignore = Name ?* and then re-adding every path that contains a slash with ignorenot = Path */*, which didn't work as expected since not ignoring directories doesn't work this way.

It seems to be a very simple issue, but I can't get my head around it.

fixer1234
  • 28,064
soriak
  • 221

1 Answers1

1

It appears that it's not possible to do exactly what you want. When Unison syncs a file versus a directory, Unison can tell the difference between the two, but Unison doesn't refer to them differently (e.g. by prefixing a / to directories or something) in a way that allows a user to pattern-match against one or the other. For example, if you sync a directory named deer and a file named phil under the root ROOT, Unison sees them named as

new dir  ---->      ROOT/deer
new file ---->      ROOT/phil

You can't distinguish between ROOT/deer and ROOT/phil. Here are some suggestions though

  1. Manually specify the directories you want synced by adding a line path = deer to your profile for each directory. I think this is the standard way to configure Unison anyways. Then for any files in your root directory you want synced too, say a file named phil, you can move phil into a directory that gets synced like deer/synced-root-files/ and then add a symbolic link from that file back to your root directory

    cd ROOT; ln -s ROOT/deer/synced-root-files/phil
    
  2. Invent a naming convention in your root directory that you can pattern match against. For example, name all and only the files you don't want to sync something like ignore.phil, and add a line to your Unison profile ignore = Path ignore.*.

Here's a link to the Path Specification and Ignoring Paths sections of the Unison manual so future readers can easily find it.