diff options
author | Adam Borowski <kilobyte@angband.pl> | 2010-10-06 23:54:27 +0200 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2010-10-07 00:35:26 +0200 |
commit | 4ef016b9b477eb660c79c739442367c64ecdb377 (patch) | |
tree | 2a74022277c713ff0bdbede5b7f402aceb0a5efc /crawl-ref/source/package.cc | |
parent | 26fd388bba0f4a8124f8c59c84797d2c8df19e6c (diff) | |
download | crawl-ref-4ef016b9b477eb660c79c739442367c64ecdb377.tar.gz crawl-ref-4ef016b9b477eb660c79c739442367c64ecdb377.zip |
Move unlinking save files to the save code itself.
This fixes --edit-save foo repack on Windows, and is safer in case the
player's name ever changes (might be possible if we add that "read morgue"
functionality).
Diffstat (limited to 'crawl-ref/source/package.cc')
-rw-r--r-- | crawl-ref/source/package.cc | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/crawl-ref/source/package.cc b/crawl-ref/source/package.cc index 399aace955..18f48b4dcb 100644 --- a/crawl-ref/source/package.cc +++ b/crawl-ref/source/package.cc @@ -93,6 +93,7 @@ package::package(const char* file, bool writeable, bool empty) { dprintf("package: initializing file=\"%s\" rw=%d\n", file, writeable); ASSERT(writeable || !empty); + filename = file; rw = writeable; if (empty) @@ -173,9 +174,10 @@ package::~package() } // all errors here should be cached write errors - if (close(fd) && !aborted) - sysfail(rw ? "write error while saving" - : "can't close the save I've just read???"); + if (fd != -1) + if (close(fd) && !aborted) + sysfail(rw ? "write error while saving" + : "can't close the save I've just read???"); dprintf("package: closed\n"); } @@ -519,6 +521,14 @@ void package::abort() aborted = true; } +void package::unlink() +{ + abort(); + close(fd); + fd = -1; + ::unlink(filename.c_str()); +} + chunk_writer::chunk_writer(package *parent, const std::string _name) : first_block(0), cur_block(0), block_len(0) |