Thanks Jan. Right. I'm familiar with the reference counting of files on unixies and the default file locking on Windoze without specifying that sharing should be allowed.
My use case is keeping a scientific notebook on disk. The notebook file is (or should be!) append-only. And I'm trying very hard to preserve its contents at points in time; for example by also committing it to git for version control. So imagine my surprise when my notebook starts dropping appends on the floor. Yikes. Simply because I've also added the notebook to version control. The opposite of what I hoped to achieve has occurred: instead of preserving updates, now updates are being dropped. Ouch. I'm trying my original suggestion now: doing a Stat before and after the write, and noticing if the new bytes are not hitting disk. It seems cumbersome, but its better than losing an experiment setup and its outcome. On Sunday, December 10, 2023 at 4:59:47 PM UTC Jan Mercl wrote: > On Sun, Dec 10, 2023 at 5:41 PM Jason E. Aten <j.e....@gmail.com> wrote: > > > My question is: is there a way to have the Go process detect if the file > it is writing to has been deleted by another process (git in this case) so > that attempting to append to the file is no longer effective? > > It is effective and [most] operations on the file continue to work as > usual. "Removing" a file, like in `os.Remove` is just removing one > reference to it. Only when the reference count drops to zero is the > file deleted. > > This is, AFAIK, how nixes work and it's IMO actually a neat feature. > It enables, for example, updating files without disrupting processes > that have those files opened. Less advanced operating systems, to > achieve the same effect, have to reboot etc. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ecc618fb-585d-4c3a-afb8-ade6f718a7bfn%40googlegroups.com.