From 99e9af0c4242aef7f3cde3274d7b75968b3b245d Mon Sep 17 00:00:00 2001 From: Adam Borowski Date: Wed, 25 Nov 2009 15:54:57 +0100 Subject: Remove unportable hacks from the invocation of tar. --- crawl-ref/source/AppHdr.h | 6 ++---- crawl-ref/source/files.cc | 35 ++++++++++++++++++++++++++++++++--- crawl-ref/source/files.h | 4 ++++ crawl-ref/source/makefile | 2 +- 4 files changed, 39 insertions(+), 8 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/AppHdr.h b/crawl-ref/source/AppHdr.h index e2be883659..1b43a1e646 100644 --- a/crawl-ref/source/AppHdr.h +++ b/crawl-ref/source/AppHdr.h @@ -461,16 +461,14 @@ // To avoid compression entirely, define SAVE_PACKAGE_NONE. #ifndef SAVE_PACKAGE_NONE #ifdef USE_TAR - // The --absolute-names switch is only there to suppress noise on stdout. - // All the paths are removed later by --transform. #define PACKAGE_SUFFIX ".tar.gz" - #define SAVE_PACKAGE_CMD "tar -zcf %s"PACKAGE_SUFFIX" --remove-files --absolute-names --transform=s:.*/:: %s.*" + #define SAVE_PACKAGE_CMD "tar" #define LOAD_UNPACKAGE_CMD "tar -zxf %s"PACKAGE_SUFFIX" -C %s" #define UNPACK_SPECIFIC_FILE_CMD LOAD_UNPACKAGE_CMD " %s" #else #ifdef USE_ZIP #define PACKAGE_SUFFIX ".zip" - #define SAVE_PACKAGE_CMD "/usr/bin/zip -m -q -j -1 %s"PACKAGE_SUFFIX" %s.*" + #define SAVE_PACKAGE_CMD "/usr/bin/zip -m -q -j" #define LOAD_UNPACKAGE_CMD "/usr/bin/unzip -q -o %s"PACKAGE_SUFFIX" -d %s" #define UNPACK_SPECIFIC_FILE_CMD LOAD_UNPACKAGE_CMD " %s" #endif diff --git a/crawl-ref/source/files.cc b/crawl-ref/source/files.cc index 896ea8f849..97f00a56f0 100644 --- a/crawl-ref/source/files.cc +++ b/crawl-ref/source/files.cc @@ -770,6 +770,22 @@ std::string get_savedir_filename(const std::string &prefix, { std::string result = Options.save_dir; + result += get_save_filename(prefix, suffix, extension, suppress_uid); + +#ifdef TARGET_OS_DOS + uppercase(result); +#endif + + return result; +} + +std::string get_save_filename(const std::string &prefix, + const std::string &suffix, + const std::string &extension, + bool suppress_uid) +{ + std::string result = ""; + // Shorten string as appropriate result += strip_filename_unsafe_chars(prefix).substr(0, kFileNameLen); @@ -1681,20 +1697,33 @@ static void _save_game_exit() clrscr(); #ifdef SAVE_PACKAGE_CMD - std::string basename = get_savedir_filename(you.your_name, "", ""); + std::string dirname = get_savedir(); + escape_path_spaces(dirname); + std::string basename = get_save_filename(you.your_name, "", ""); escape_path_spaces(basename); char cmd_buff[1024]; +#ifdef USE_TAR snprintf( cmd_buff, sizeof(cmd_buff), - SAVE_PACKAGE_CMD, basename.c_str(), basename.c_str() ); + "cd %s && "SAVE_PACKAGE_CMD" -zcf %s"PACKAGE_SUFFIX" --remove-files %s.*", + dirname.c_str(), basename.c_str(), basename.c_str()); +#else +# ifdef USE_ZIP + snprintf( cmd_buff, sizeof(cmd_buff), + SAVE_PACKAGE_CMD" %s"PACKAGE_SUFFIX" %s.*", + (dirname+basename).c_str(), (dirname+basename).c_str()); +# else + No save package defined. +#endif +#endif if (system( cmd_buff ) != 0) { cprintf( EOL "Warning: Zip command (SAVE_PACKAGE_CMD) returned " "non-zero value!" EOL ); } - DO_CHMOD_PRIVATE ( (basename + PACKAGE_SUFFIX).c_str() ); + DO_CHMOD_PRIVATE ( (dirname + basename + PACKAGE_SUFFIX).c_str() ); #endif #ifdef DGL_WHEREIS diff --git a/crawl-ref/source/files.h b/crawl-ref/source/files.h index 175bc9aa77..d81e23240e 100644 --- a/crawl-ref/source/files.h +++ b/crawl-ref/source/files.h @@ -62,6 +62,10 @@ bool travel_load_map( branch_type branch, int absdepth ); std::vector find_saved_characters(); std::string get_savedir(); +std::string get_save_filename(const std::string &pre, + const std::string &suf, + const std::string &ext, + bool suppress_uid = false); std::string get_savedir_filename(const std::string &pre, const std::string &suf, const std::string &ext, diff --git a/crawl-ref/source/makefile b/crawl-ref/source/makefile index d81586e106..1a2364bca8 100644 --- a/crawl-ref/source/makefile +++ b/crawl-ref/source/makefile @@ -182,7 +182,7 @@ ifneq (,$(findstring CYGWIN,$(uname_S))) NO_RDYNAMIC = YesPlease BUILD_PCRE = YesPlease endif -ifneq ($(GAME),crawl.exe) +ifeq (,$(findstring .exe,$(GAME))) DEFINES += -DUSE_TAR else DEFINES += -DUSE_ZIP -- cgit v1.2.3-54-g00ecf