[Haskell-cafe] How to move files?
YueCompl
compl.yue at icloud.com
Thu Apr 15 09:27:16 UTC 2021
I'm not sure you need this, but on shared filesystem (nfs e.g.), to implement generate-on-demand fashioned data production with parallelism, a trick is to create a temporary directory that exclusively named by your particular run of the critical section of the code. Expect failure from the os in creation of a generated name in location where your final file would go, to ensure same filesystem, and decorate it (with the value from a local counter e.g.) to not appear as the ultimately desired path/name - if failed, try another name; otherwise you succeeded, you are sure this dir is exclusive per your current execution thread, then generate the data (which would take time) and put the payload into a file inside this dir, then fsync to make sure the storage is permanent, then rename it to the ultimate file path/name you'd like it to be. Maybe another parallel process did the same thing and race to overwrite your production, that'll be fine as long as the file data generation algorithm holds some invariant, you'll never have a corrupted/incomplete file on the expected path/name this way.
I suggest this is never a Haskell thing but os tricks per se.
> On 2021-04-15, at 17:05, Sven Panne <svenpanne at gmail.com> wrote:
>
> Am Do., 15. Apr. 2021 um 10:24 Uhr schrieb Daniel Trstenjak <daniel.trstenjak at gmail.com <mailto:daniel.trstenjak at gmail.com>>:
> And it's the safest, because a move is an atomic operation [...]
>
> ... unless you are on Windows. ;-)
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210415/ca710794/attachment.html>
More information about the Haskell-Cafe
mailing list