Overview
Comment: | OFZIP: Add an option to manually specify the type |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ea478372d8d54025903b3b64e835688d |
User & Date: | js on 2016-05-22 21:30:17 |
Other Links: | manifest | tags |
Context
2016-05-28
| ||
09:48 | OFTarArchiveEntry: Fix type, add an explicit cast check-in: 07d8cd5590 user: js tags: trunk | |
2016-05-22
| ||
21:30 | OFZIP: Add an option to manually specify the type check-in: ea478372d8 user: js tags: trunk | |
21:14 | OFTarArchive.h: Fix a typo check-in: 804809a28e user: js tags: trunk | |
Changes
Modified utils/ofzip/OFZIP.h from [bd013d1605] to [3f9ff29ba8].
︙ | ︙ | |||
24 25 26 27 28 29 30 | int8_t _overwrite; @public int8_t _outputLevel; OFString *_archivePath; int _exitStatus; } | | > | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | int8_t _overwrite; @public int8_t _outputLevel; OFString *_archivePath; int _exitStatus; } - (id <Archive>)openArchiveWithPath: (OFString*)path type: (OFString*)type; - (bool)shouldExtractFile: (OFString*)fileName outFileName: (OFString*)outFileName; - (ssize_t)copyBlockFromStream: (OFStream*)input toStream: (OFStream*)output fileName: (OFString*)fileName; @end |
Modified utils/ofzip/OFZIP.m from [45c0a2620e] to [080598e862].
︙ | ︙ | |||
40 41 42 43 44 45 46 | OF_APPLICATION_DELEGATE(OFZIP) static void help(OFStream *stream, bool full, int status) { [stream writeFormat: | | > | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | OF_APPLICATION_DELEGATE(OFZIP) static void help(OFStream *stream, bool full, int status) { [stream writeFormat: @"Usage: %@ -[fhlnpqtvx] archive.zip [file1 file2 ...]\n", [OFApplication programName]]; if (full) [stream writeString: @"\nOptions:\n" @" -f --force Force / overwrite files\n" @" -h --help Show this help\n" @" -l --list List all files in the archive\n" @" -n --no-clober Never overwrite files\n" @" -p --print Print one or more files from the " @"archive\n" @" -q --quiet Quiet mode (no output, except " @"errors)\n" @" -t --type Archive type (gz, tar, tgz, zip)\n" @" -v --verbose Verbose output for file list\n" @" -x --extract Extract files\n"]; [OFApplication terminateWithStatus: status]; } static void |
︙ | ︙ | |||
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | longOption2, shortOption3, longOption3]; [OFApplication terminateWithStatus: 1]; } @implementation OFZIP - (void)applicationDidFinishLaunching { const of_options_parser_option_t options[] = { { 'f', @"force", 0, NULL, NULL }, { 'h', @"help", 0, NULL, NULL }, { 'l', @"list", 0, NULL, NULL }, { 'n', @"no-clobber", 0, NULL, NULL }, { 'p', @"print", 0, NULL, NULL }, { 'q', @"quiet", 0, NULL, NULL }, { 'v', @"verbose", 0, NULL, NULL }, { 'x', @"extract", 0, NULL, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser = [OFOptionsParser parserWithOptions: options]; of_unichar_t option, mode = '\0'; | > > | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | longOption2, shortOption3, longOption3]; [OFApplication terminateWithStatus: 1]; } @implementation OFZIP - (void)applicationDidFinishLaunching { OFString *type = nil; const of_options_parser_option_t options[] = { { 'f', @"force", 0, NULL, NULL }, { 'h', @"help", 0, NULL, NULL }, { 'l', @"list", 0, NULL, NULL }, { 'n', @"no-clobber", 0, NULL, NULL }, { 'p', @"print", 0, NULL, NULL }, { 'q', @"quiet", 0, NULL, NULL }, { 't', @"type", 1, NULL, &type }, { 'v', @"verbose", 0, NULL, NULL }, { 'x', @"extract", 0, NULL, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser = [OFOptionsParser parserWithOptions: options]; of_unichar_t option, mode = '\0'; |
︙ | ︙ | |||
153 154 155 156 157 158 159 | [of_stderr writeFormat: @"%@: Option --%@ takes no " @"argument!\n", [OFApplication programName], [optionsParser lastLongOption]]; [OFApplication terminateWithStatus: 1]; break; | | | > | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | [of_stderr writeFormat: @"%@: Option --%@ takes no " @"argument!\n", [OFApplication programName], [optionsParser lastLongOption]]; [OFApplication terminateWithStatus: 1]; break; case '?': if ([optionsParser lastLongOption] != nil) [of_stderr writeFormat: @"%@: Unknown option: --%@\n", [OFApplication programName], [optionsParser lastLongOption]]; else [of_stderr writeFormat: @"%@: Unknown option: -%C\n", [OFApplication programName], [optionsParser lastOption]]; [OFApplication terminateWithStatus: 1]; } } remainingArguments = [optionsParser remainingArguments]; archive = [self openArchiveWithPath: [remainingArguments firstObject] type: type]; switch (mode) { case 'l': if ([remainingArguments count] != 1) help(of_stderr, false, 1); [archive listFiles]; |
︙ | ︙ | |||
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | break; } [OFApplication terminateWithStatus: _exitStatus]; } - (id <Archive>)openArchiveWithPath: (OFString*)path { OFFile *file = nil; id <Archive> archive = nil; [_archivePath release]; _archivePath = [path copy]; if (path == nil) return nil; @try { file = [OFFile fileWithPath: path mode: @"rb"]; } @catch (OFOpenItemFailedException *e) { [of_stderr writeFormat: @"Failed to open file %@: %s\n", [e path], strerror([e errNo])]; [OFApplication terminateWithStatus: 1]; } | > | | < > > > > > > > > > | | > > > > > > > > | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | break; } [OFApplication terminateWithStatus: _exitStatus]; } - (id <Archive>)openArchiveWithPath: (OFString*)path type: (OFString*)type { OFFile *file = nil; id <Archive> archive = nil; [_archivePath release]; _archivePath = [path copy]; if (path == nil) return nil; @try { file = [OFFile fileWithPath: path mode: @"rb"]; } @catch (OFOpenItemFailedException *e) { [of_stderr writeFormat: @"Failed to open file %@: %s\n", [e path], strerror([e errNo])]; [OFApplication terminateWithStatus: 1]; } if (type == nil || [type isEqual: @"auto"]) { /* This one has to be first for obvious reasons */ if ([path hasSuffix: @".tar.gz"] || [path hasSuffix: @".tgz"] || [path hasSuffix: @".TAR.GZ"] || [path hasSuffix: @".TGZ"]) type = @"tgz"; else if ([path hasSuffix: @".gz"] || [path hasSuffix: @".GZ"]) type = @"gz"; else if ([path hasSuffix: @".tar"] || [path hasSuffix: @".TAR"]) type = @"tar"; else type = @"zip"; } @try { if ([type isEqual: @"gz"]) archive = [GZIPArchive archiveWithStream: file]; else if ([type isEqual: @"tar"]) archive = [TarArchive archiveWithStream: file]; else if ([type isEqual: @"tgz"]) archive = [TarArchive archiveWithStream: [OFGZIPStream streamWithStream: file]]; else if ([type isEqual: @"zip"]) archive = [ZIPArchive archiveWithStream: file]; else { [of_stderr writeFormat: @"Unknown archive type: %@!\n", type]; [OFApplication terminateWithStatus: 1]; } } @catch (OFReadFailedException *e) { [of_stderr writeFormat: @"Failed to read file %@: %s\n", path, strerror([e errNo])]; [OFApplication terminateWithStatus: 1]; } @catch (OFInvalidFormatException *e) { [of_stderr writeFormat: @"File %@ is not a valid archive!\n", path]; |
︙ | ︙ |