llvm.org GIT mirror llvm / 7ad2fa3
Use a range loop. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242153 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
1 changed file(s) with 17 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
294294
295295 // Implements the 'p' operation. This function traverses the archive
296296 // looking for members that match the path list.
297 static void doPrint(StringRef Name, object::Archive::child_iterator I) {
297 static void doPrint(StringRef Name, const object::Archive::Child &C) {
298298 if (Verbose)
299299 outs() << "Printing " << Name << "\n";
300300
301 StringRef Data = I->getBuffer();
301 StringRef Data = C.getBuffer();
302302 outs().write(Data.data(), Data.size());
303303 }
304304
323323 // the file names of each of the members. However, if verbose mode is requested
324324 // ('v' modifier) then the file type, permission mode, user, group, size, and
325325 // modification time are also printed.
326 static void doDisplayTable(StringRef Name, object::Archive::child_iterator I) {
326 static void doDisplayTable(StringRef Name, const object::Archive::Child &C) {
327327 if (Verbose) {
328 sys::fs::perms Mode = I->getAccessMode();
328 sys::fs::perms Mode = C.getAccessMode();
329329 printMode((Mode >> 6) & 007);
330330 printMode((Mode >> 3) & 007);
331331 printMode(Mode & 007);
332 outs() << ' ' << I->getUID();
333 outs() << '/' << I->getGID();
334 outs() << ' ' << format("%6llu", I->getSize());
335 outs() << ' ' << I->getLastModified().str();
332 outs() << ' ' << C.getUID();
333 outs() << '/' << C.getGID();
334 outs() << ' ' << format("%6llu", C.getSize());
335 outs() << ' ' << C.getLastModified().str();
336336 outs() << ' ';
337337 }
338338 outs() << Name << "\n";
340340
341341 // Implement the 'x' operation. This function extracts files back to the file
342342 // system.
343 static void doExtract(StringRef Name, object::Archive::child_iterator I) {
343 static void doExtract(StringRef Name, const object::Archive::Child &C) {
344344 // Retain the original mode.
345 sys::fs::perms Mode = I->getAccessMode();
345 sys::fs::perms Mode = C.getAccessMode();
346346 SmallString<128> Storage = Name;
347347
348348 int FD;
354354 raw_fd_ostream file(FD, false);
355355
356356 // Get the data and its length
357 StringRef Data = I->getBuffer();
357 StringRef Data = C.getBuffer();
358358
359359 // Write the data.
360360 file.write(Data.data(), Data.size());
364364 // now.
365365 if (OriginalDates)
366366 failIfError(
367 sys::fs::setLastModificationAndAccessTime(FD, I->getLastModified()));
367 sys::fs::setLastModificationAndAccessTime(FD, C.getLastModified()));
368368
369369 if (close(FD))
370370 fail("Could not close the file");
390390
391391 static void performReadOperation(ArchiveOperation Operation,
392392 object::Archive *OldArchive) {
393 for (object::Archive::child_iterator I = OldArchive->child_begin(),
394 E = OldArchive->child_end();
395 I != E; ++I) {
396 ErrorOr NameOrErr = I->getName();
393 for (const object::Archive::Child &C : OldArchive->children()) {
394 ErrorOr NameOrErr = C.getName();
397395 failIfError(NameOrErr.getError());
398396 StringRef Name = NameOrErr.get();
399397
405403 default:
406404 llvm_unreachable("Not a read operation");
407405 case Print:
408 doPrint(Name, I);
406 doPrint(Name, C);
409407 break;
410408 case DisplayTable:
411 doDisplayTable(Name, I);
409 doDisplayTable(Name, C);
412410 break;
413411 case Extract:
414 doExtract(Name, I);
412 doExtract(Name, C);
415413 break;
416414 }
417415 }