| 50 | } |
| 51 | |
| 52 | static bool untar(const std::string& tarPath, const std::string& destinationPath) { |
| 53 | minitar mp; |
| 54 | if (minitar_open(tarPath.c_str(), &mp) != 0) { |
| 55 | perror(tarPath.c_str()); |
| 56 | return 1; |
| 57 | } |
| 58 | bool success = true; |
| 59 | minitar_entry entry; |
| 60 | |
| 61 | do { |
| 62 | if (minitar_read_entry(&mp, &entry) == 0) { |
| 63 | LOGGER.info("Extracting {}", entry.metadata.path); |
| 64 | if (entry.metadata.type == MTAR_DIRECTORY) { |
| 65 | if (!strcmp(entry.metadata.name, ".") || !strcmp(entry.metadata.name, "..") || !strcmp(entry.metadata.name, "/")) continue; |
| 66 | if (!untarDirectory(&entry, destinationPath)) { |
| 67 | LOGGER.error("Failed to create directory {}/{}: {}", destinationPath, entry.metadata.name, strerror(errno)); |
| 68 | success = false; |
| 69 | break; |
| 70 | } |
| 71 | } else if (entry.metadata.type == MTAR_REGULAR) { |
| 72 | if (!untarFile(&mp, &entry, destinationPath)) { |
| 73 | LOGGER.error("Failed to extract file {}: {}", entry.metadata.path, strerror(errno)); |
| 74 | success = false; |
| 75 | break; |
| 76 | } |
| 77 | } else if (entry.metadata.type == MTAR_SYMLINK) { |
| 78 | LOGGER.error("SYMLINK not supported"); |
| 79 | } else if (entry.metadata.type == MTAR_HARDLINK) { |
| 80 | LOGGER.error("HARDLINK not supported"); |
| 81 | } else if (entry.metadata.type == MTAR_FIFO) { |
| 82 | LOGGER.error("FIFO not supported"); |
| 83 | } else if (entry.metadata.type == MTAR_BLKDEV) { |
| 84 | LOGGER.error("BLKDEV not supported"); |
| 85 | } else if (entry.metadata.type == MTAR_CHRDEV) { |
| 86 | LOGGER.error("CHRDEV not supported"); |
| 87 | } else { |
| 88 | LOGGER.error("Unknown entry type: {}", static_cast<int>(entry.metadata.type)); |
| 89 | success = false; |
| 90 | break; |
| 91 | } |
| 92 | } else break; |
| 93 | } while (true); |
| 94 | minitar_close(&mp); |
| 95 | return success; |
| 96 | } |
| 97 | |
| 98 | void cleanupInstallDirectory(const std::string& path) { |
| 99 | if (!file::deleteRecursively(path)) { |
no test coverage detected