0

Bit of a niche question this, but I want to atomically replace a directory with a symlink to itself under a different name.

Specifically, I have a directory ./node_modules, and I want to move it to ./node_modules.nosync and link the old path to the new path (./node_modules -> ./node_modules.nosync). This is because I want to stop iCloud from messing with it - long story. And I want to perform that operation while another process is writing to that path.

I'm looking to do something similar to this or this, but involving a directory.

I was originally thinking of holding some kind of lock on the path so that the other process writing to it stalls, but from what I can tell you can't hold a lock on a directory path on macOS.

deeBo
  • 101
  • 2
  • 3
    If something is writing to a file in that directory then you can rename the directory without impacting the write; the _filehandle_ is what is being written, not the path. Indeed, after the rename the `node_modules.nosync/file` will still be written to, until the filehandle is closed. – Stephen Harris Feb 21 '23 at 01:51

0 Answers0