Differences From Artifact [50de2565fd]:
- File
utils/ofzip/TarArchive.m
— part of check-in
[41949ecc65]
at
2017-08-05 17:48:55
on branch trunk
— ofzip: Support for writing files
Not supported for any file formats, yet. (user: js, size: 11228) [annotate] [blame] [check-ins using]
To Artifact [4669023b91]:
- File utils/ofzip/TarArchive.m — part of check-in [ddfb995c90] at 2017-08-05 21:39:59 on branch trunk — ofzip: Support for creating / appending tar files (user: js, size: 14209) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
422 423 424 425 426 427 428 429 | for (OFString *file in files) { [of_stderr writeLine: OF_LOCALIZED(@"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } @end | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | for (OFString *file in files) { [of_stderr writeLine: OF_LOCALIZED(@"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; if ([files count] < 1) { [of_stderr writeLine: OF_LOCALIZED(@"add_no_file_specified", @"Need one or more files to add!")]; app->_exitStatus = 1; return; } for (OFString *fileName in files) { void *pool = objc_autoreleasePoolPush(); OFMutableTarArchiveEntry *entry; OFStream *output; if (app->_outputLevel >= 0) [of_stdout writeString: OF_LOCALIZED(@"adding_file", @"Adding %[file]...", @"file", fileName)]; entry = [OFMutableTarArchiveEntry entryWithFileName: fileName]; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS [entry setMode: [fileManager permissionsOfItemAtPath: fileName]]; #endif [entry setSize: [fileManager sizeOfFileAtPath: fileName]]; [entry setModificationDate: [fileManager modificationTimeOfItemAtPath: fileName]]; #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER OFString *owner, *group; [fileManager getOwner: &owner group: &group ofItemAtPath: fileName]; [entry setOwner: owner]; [entry setGroup: group]; #endif if ([fileManager fileExistsAtPath: fileName]) [entry setType: OF_TAR_ARCHIVE_ENTRY_TYPE_FILE]; else if ([fileManager directoryExistsAtPath: fileName]) { [entry setType: OF_TAR_ARCHIVE_ENTRY_TYPE_DIRECTORY]; [entry setSize: 0]; } else if ([fileManager symbolicLinkExistsAtPath: fileName]) { [entry setType: OF_TAR_ARCHIVE_ENTRY_TYPE_SYMLINK]; [entry setTargetFileName: [fileManager destinationOfSymbolicLinkAtPath: fileName]]; [entry setSize: 0]; } [entry makeImmutable]; output = [_archive streamForWritingEntry: entry]; if ([entry type] == OF_TAR_ARCHIVE_ENTRY_TYPE_FILE) { uint64_t written = 0, size = [entry size]; int8_t percent = -1, newPercent; OFFile *input = [OFFile fileWithPath: fileName mode: @"r"]; while (![input isAtEndOfStream]) { ssize_t length = [app copyBlockFromStream: input toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; goto outer_loop_end; } written += length; newPercent = (written == size ? 100 : (int8_t)(written * 100 / size)); if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [of_stdout writeString: @"\r"]; [of_stdout writeString: OF_LOCALIZED( @"adding_file_percent", @"Adding %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } } if (app->_outputLevel >= 0) { [of_stdout writeString: @"\r"]; [of_stdout writeLine: OF_LOCALIZED( @"adding_file_done", @"Adding %[file]... done", @"file", fileName)]; } [output close]; outer_loop_end: objc_autoreleasePoolPop(pool); } [_archive close]; } @end |