Ticket #997 (closed defect: invalid)

Opened 21 months ago

Last modified 21 months ago

with-open-file wrapper deletes files on pop from break

Reported by: jshrager Owned by:
Priority: normal Milestone:
Component: other Version: trunk
Keywords: Cc:

Description

If I get a break inside a with-open-file and abort to the top level, the files to that point are deleted. This is weird and makes degugging difficult, esp. when I'm doing long complex computations that generate partial results, and expect to be able to dump them into files and then use them on restart to figure out where I was and what happened. It would be nice, if you're not going to change this behavior, to have a switch for wof that would leave the files around in this case.

Change History

comment:1 Changed 21 months ago by gb

  • Status changed from new to closed
  • Resolution set to invalid

The CLHS dictionary entry for WITH-OPEN-FILE says: "When control leaves the body, either normally or abnormally (such as by use of throw), the file is automatically closed. If a new output file is being written, and control leaves abnormally, the file is aborted and the file system is left, so far as possible, as if the file had never been opened."

In other words, WITH-OPEN-FILE is supposed to behave the way it does in this case.

comment:2 Changed 21 months ago by jshrager

Okay, I guess I can't argue with the CLHS, but it's stupid, and BTW, most other Lisps that I've used do NOT behave this way. The reason that it's stupid is that it's lossy -- if you superseded an already existing file, you can't get it back, so why destroy your partial results.

I know, I know ... take it up with the spec.

(Actually, I COULD interpret "a new output file" as not including when a file is superseded...but I know that this is a non-starter argument.)

I'm just really unhappy with deleting a potential ton of output done by the user.

Whatever.

comment:3 follow-up: ↓ 4 Changed 21 months ago by jshrager

ps. ACL does NOT delete the file!

comment:4 in reply to: ↑ 3 Changed 21 months ago by gb

Replying to jshrager:

ps. ACL does NOT delete the file!

Neither does CLISP. I have no idea whether this is intentional or not in either case.

CMUCL, LispWorks?, SBCL, and CCL do delete newly-created files.

You seem to be depending on non-compliant behavior (and, to the extent that I can understand what you say above, misunderstanding what happens if an existing file is opened with :IF-EXISTS :SUPERSEDE and the form is exited abnormally. See also the dictionary entry for CLOSE and its discussion of the :ABORT option.)

Note: See TracTickets for help on using tickets.