taruss
4/19/2016 6:18:00 PM
On Tuesday, April 19, 2016 at 2:47:46 AM UTC-7, Jim Newton wrote:
> Does anyone know if there's a way to tell OPEN to not override the backup file?
>
> Using (open "file" :direction :output :if-exists :rename)
> The first time it causes "file" to be created.
> The second time "file" is renamed to "file.bak" (on SBCL) and "file" is created anew.
> The third time "file" is renamed to "file.bak" losing the previous "file.bak".
>
> If I want to prevent these files from being deleted, I can of course write code to do that,
> by just checking and renaming "file" before calling open.
> But it seems like OPEN almost has this capability already. Does anyone know whether
> it's somehow built-in?
Let's try a real answer this time.
It seems like :if-exists :new-version should be what you want.
But when I tried this in SBCL on Unix, it failed with the somewhat curious
message:
"OPEN :IF-EXISTS :NEW-VERSION is not supported when a new version must be created."
But this is perhaps an issue with native file system support. Under VAX VMS
the native file system supported versions for files, so there was a native
support for this. I suppose one could choose to do something like the Emacs
convention of *.~1~, *.~2~, etc. but that might be too heroic for the lisp
implementation to want to support, since it isn't universal.
I guess .bak is more standard.
But the real answer is that if you want to manage the file actions in detail,
you will probably have to implement your own management strategy.