- (cond (arg1
- ;; We got us an abort on our hands.
- (when (fd-stream-handler stream)
- (sb!sys:remove-fd-handler (fd-stream-handler stream))
- (setf (fd-stream-handler stream) nil))
- (when (and (fd-stream-file stream)
- (fd-stream-obuf-sap stream))
- ;; We can't do anything unless we know what file were
- ;; dealing with, and we don't want to do anything
- ;; strange unless we were writing to the file.
- (if (fd-stream-original stream)
- ;; We have a handle on the original, just revert.
+ (cond (arg1 ; We got us an abort on our hands.
+ (when (fd-stream-handler fd-stream)
+ (sb!sys:remove-fd-handler (fd-stream-handler fd-stream))
+ (setf (fd-stream-handler fd-stream) nil))
+ ;; We can't do anything unless we know what file were
+ ;; dealing with, and we don't want to do anything
+ ;; strange unless we were writing to the file.
+ (when (and (fd-stream-file fd-stream)
+ (fd-stream-obuf-sap fd-stream))
+ (if (fd-stream-original fd-stream)
+ ;; If the original is EQ to file we are appending
+ ;; and can just close the file without renaming.
+ (unless (eq (fd-stream-original fd-stream)
+ (fd-stream-file fd-stream))
+ ;; We have a handle on the original, just revert.
+ (multiple-value-bind (okay err)
+ (sb!unix:unix-rename (fd-stream-original fd-stream)
+ (fd-stream-file fd-stream))
+ (unless okay
+ (simple-stream-perror
+ "couldn't restore ~S to its original contents"
+ fd-stream
+ err))))
+ ;; We can't restore the original, and aren't
+ ;; appending, so nuke that puppy.
+ ;;
+ ;; FIXME: This is currently the fate of superseded
+ ;; files, and according to the CLOSE spec this is
+ ;; wrong. However, there seems to be no clean way to
+ ;; do that that doesn't involve either copying the
+ ;; data (bad if the :abort resulted from a full
+ ;; disk), or renaming the old file temporarily
+ ;; (probably bad because stream opening becomes more
+ ;; racy).