From e1009320688e35d759414a71b4b49f4bd8bfc433 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sun, 5 Sep 2004 10:12:53 +0000 Subject: [PATCH] Yes, I know it is ugly. Removed gunzip and tar. It does still rely on /bin/cp being there, but that is mostly because I was too lazy to write a replacement for it. --- .../PBProject/Installer/BuildInstaller.cpp | 51 +++-------- stepmania/PBProject/Installer/Helper.mm | 31 ++++--- stepmania/PBProject/Installer/Processor.cpp | 90 +++++-------------- stepmania/PBProject/Installer/Processor.h | 4 +- stepmania/PBProject/Installer/Util.cpp | 41 +++++++++ stepmania/PBProject/Installer/Util.h | 2 + 6 files changed, 97 insertions(+), 122 deletions(-) diff --git a/stepmania/PBProject/Installer/BuildInstaller.cpp b/stepmania/PBProject/Installer/BuildInstaller.cpp index eb2aa30ada..735d08399a 100644 --- a/stepmania/PBProject/Installer/BuildInstaller.cpp +++ b/stepmania/PBProject/Installer/BuildInstaller.cpp @@ -25,34 +25,20 @@ using namespace std; #include "Util.h" void HandleFile(const CString& file, const CString& dir, - const CString& archivePath, bool overwrite) + const CString& archivePath) { - static bool archiveMade = false; - char path[] = "/usr/bin/tar"; - char arg1[] = "-rf"; - char arg2[archivePath.length() + 1]; - char arg3[] = "-C"; - char arg4[dir.length() + 1]; - char arg5[file.length() + 1]; - - if (!archiveMade) - { - arg1[1] = 'c'; - archiveMade = true; - } - - strcpy(arg2, archivePath); - strcpy(arg4, dir); - strcpy(arg5, file); - - int r; - if ((r = CallTool2(true, -1, -1, -1, path, arg1, arg2, arg3, arg4, - arg5, NULL)) != 0) - { - fprintf(stderr, "%s %s %s %s %s %s returned %d\n", - path, arg1, arg2, arg3, arg4, arg5, r); - exit(-10); - } + CString from = dir + '/' + file; + CString to = archivePath + '/' + file; + char copy[] = "/bin/cp"; + char arg[] = "-R"; + + MakeAllButLast(to); + if (CallTool(copy, arg, from.c_str(), to.c_str(), NULL)) + { + fprintf(stderr, "Couldn't copy file from \"%s\" to \"%s\".", + from.c_str(), to.c_str()); + exit(-10); + } } const CString GetPath(const CString& ID) @@ -139,22 +125,13 @@ int main(int argc, char *argv[]) return 4; } - CString archivePath = outDir + "/archive.tar"; + CString archivePath = outDir; Processor p(archivePath, HandleFile, GetPath, NULL, false); while (nextLine < config.GetNumLines()) p.ProcessLine(config.GetLine(nextLine), nextLine); - printf("Compressing the archive.\n"); - - char toolPath[] = "/usr/bin/gzip"; - if (CallTool(toolPath, archivePath.c_str(), NULL)) - { - printf("Gzip failed.\n"); - return 6; - } - if (!config.WriteFile(outDir + "/config")) { printf("%s\n", strerror(errno)); diff --git a/stepmania/PBProject/Installer/Helper.mm b/stepmania/PBProject/Installer/Helper.mm index e1ffd693ab..825d4e63ca 100644 --- a/stepmania/PBProject/Installer/Helper.mm +++ b/stepmania/PBProject/Installer/Helper.mm @@ -22,28 +22,26 @@ void Error(const char *fmt, ...); static id c; void HandleFile(const CString& file, const CString& dir, - const CString& archivePath, bool overwrite) + const CString& archivePath) { NSString *filePath = [NSString stringWithCString:dir]; filePath = [filePath stringByAppendingFormat:@"%s%s", (dir == "/" ? "" : "/"), file.c_str()]; - if (!overwrite && DoesFileExist([filePath cString])) - return; [c postMessage:filePath]; /* This is rediculus */ - char f[file.length() + 1]; - char d[dir.length() + 1]; - char p[archivePath.length() + 1]; - char path[] = "/usr/bin/tar"; - char arg1[] = "-xPf"; - char arg3[] = "-C"; - char *const arguments[] = {path, arg1, p, arg3, d, f, NULL}; - - strcpy(p, archivePath); - strcpy(d, dir); - strcpy(f, file); - + char path[] = "/bin/cp"; + char arg[] = "-RP"; + CString fromString = archivePath + '/' + file; + char from[fromString.length() + 1]; + CString toString = dir + '/' + file; + char to[toString.length() + 1]; + char *const arguments[] = {path, arg, from, to, NULL}; + + strcpy(from, fromString); + strcpy(to, toString); + MakeAllButLast(to); + int fd_dev_null = open("/dev/null", O_RDWR, 0); if (CallTool3(true, -1, fd_dev_null, fileno(stderr), path, arguments)) @@ -131,7 +129,8 @@ void Echo(const CString& message, bool loud) c = caller; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; CString configPath = [mPath cString]; - CString archivePath = configPath + "/archive.tar.gz"; + //CString archivePath = configPath + "/archive.tar.gz"; + CString archivePath = configPath; BOOL success = NO; configPath += "/config"; diff --git a/stepmania/PBProject/Installer/Processor.cpp b/stepmania/PBProject/Installer/Processor.cpp index 9c89bc941b..df7410ce02 100644 --- a/stepmania/PBProject/Installer/Processor.cpp +++ b/stepmania/PBProject/Installer/Processor.cpp @@ -40,34 +40,7 @@ mError(Processor::DefaultError), mInstalling(i) getwd(cwd); mCWD = cwd; mConditionals["INSTALLING"] = i; - - if (mInstalling) - { - if (!DoesFileExist(path)) - throw CString("Archive file not present."); - - char archivePath[] = "/tmp/installerXXXXXX.tar"; - int fd = mkstemps(archivePath, 4); - - if (fd == -1) - throw CString("Couldn't create temporary file"); - - mPath = archivePath; - - char toolPath[] = "/usr/bin/gunzip"; - - try { - if(CallTool2(true, -1, fd, -1, toolPath, "-c", path.c_str(), NULL)) - throw CString("Archive file not handled correctly."); - } catch (CString& e) { - close(fd); - unlink(mPath); - throw; - } - close(fd); - } - else - mPath = path; + mPath = path; } Processor::~Processor() @@ -124,7 +97,11 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine) } if (mInstalling) - (*mHandleFile)(file, dir, mPath, ResolveConditional(parts[2])); + { + if (ResolveConditional(parts[2])) + rm_rf(dir + '/' + file); + (*mHandleFile)(file, dir, mPath); + } else { if (IsADirectory((dir == "/" ? dir : dir + "/" ) + file)) @@ -138,12 +115,12 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine) fchdir(fd); close(fd); if (list.size() == 0) //empty dir or ignored dir - (*mHandleFile)(file, dir, mPath, true); + (*mHandleFile)(file, dir, mPath); for (unsigned i=0; i(), false); - for (unsigned i=0; i %s\n", path.c_str(), dir.c_str()); + return mkdir_p(dir); +} + +void rm_rf(const CString& path) +{ + printf("deleting %s\n", path.c_str()); + if (IsADirectory(path)) + { + CStringArray files, dirs; + FileListingForDirectoryWithIgnore(path, files, dirs, set(), false); + for (unsigned i=0; i& ignore, bool ignoreDot = true); int mkdir_p(const CString& path); +int MakeAllButLast(const CString& path); +void rm_rf(const CString& path); int CallTool3(bool blocking, int fd_in, int fd_out, int fd_err, const char *path, char *const *arguments); inline int CallTool(char *path, ...) { return CallTool3(true, -1, -1, -1, path, &path); } inline int CallTool2(bool blocking, int fd_in, int fd_out, int fd_err, char *path, ...)