diff --git a/.github/workflows/build-erofs-utils.yml b/.github/workflows/build-erofs-utils.yml index b9c04b6f..babe8821 100644 --- a/.github/workflows/build-erofs-utils.yml +++ b/.github/workflows/build-erofs-utils.yml @@ -11,7 +11,7 @@ on: version: description: 'Version' required: false - default: 'v1.7-23092300' + default: 'v1.8.1-24081000' jobs: release: @@ -36,7 +36,7 @@ jobs: allowUpdates: true omitBodyDuringUpdate: true removeArtifacts: true - token: ${{ secrets.ACCESS_TOKEN }} + token: ${{ secrets.GITHUB_TOKEN }} name: ${{ github.event.inputs.version }} tag: ${{ github.event.inputs.version }} body: This release is built by github-action. diff --git a/extract/ErofsHardlinkHandle.cpp b/extract/ErofsHardlinkHandle.cpp index 23e8fbef..a56cbe51 100644 --- a/extract/ErofsHardlinkHandle.cpp +++ b/extract/ErofsHardlinkHandle.cpp @@ -1,7 +1,6 @@ #include "ErofsHardlinkHandle.h" namespace skkk { - ErofsHardlinkEntry::ErofsHardlinkEntry(uint64_t _nid, const char *_path) { this->nid = _nid; this->path = _path; diff --git a/extract/ErofsNode.cpp b/extract/ErofsNode.cpp index 55afdc83..82ad5c93 100644 --- a/extract/ErofsNode.cpp +++ b/extract/ErofsNode.cpp @@ -7,7 +7,6 @@ #define FS_CONFIG_BUF_SIZE (PATH_MAX + 256) namespace skkk { - ErofsNode::ErofsNode(const char *path, short typeId, struct erofs_inode *inode) { this->path = path; this->typeId = typeId; @@ -139,13 +138,12 @@ namespace skkk { } } - int ErofsNode::writeNodeEntity2File(const string &outDir) { + int ErofsNode::writeNodeEntity2File(const string &outDir) const { int err = RET_EXTRACT_DONE; string _tmp = outDir + path; const char *filePath = _tmp.c_str(); - const char *hardlinkSrcPath; + const char *hardlinkSrcPath = erofsHardlinkFind(nid); - hardlinkSrcPath = erofsHardlinkFind(nid); if (hardlinkSrcPath) { unique_lock lock(erofsHardlinkLock); return erofs_extract_hardlink(inode, (outDir + hardlinkSrcPath).c_str(), filePath); diff --git a/extract/ExtractHelper.cpp b/extract/ExtractHelper.cpp index ae101099..a44bec4d 100644 --- a/extract/ExtractHelper.cpp +++ b/extract/ExtractHelper.cpp @@ -20,8 +20,6 @@ #endif namespace skkk { - - static int doInitNode(const string &path, bool recursive); static int doInitNodeRecursive(erofs_nid_t nid); @@ -50,7 +48,7 @@ namespace skkk { if (eo->iter_path) { eo->iter_path[curr_pos++] = '/'; strncpy(eo->iter_path + curr_pos, ctx->dname, - ctx->de_namelen); + ctx->de_namelen); curr_pos += ctx->de_namelen; eo->iter_path[curr_pos] = '\0'; } else { @@ -73,7 +71,7 @@ namespace skkk { break; case S_IFREG: if (erofs_is_packed_inode(&inode)) [[unlikely]] - break; + break; typeId = EROFS_FT_REG_FILE; break; case S_IFLNK: @@ -100,10 +98,10 @@ namespace skkk { #else const ErofsNode *eNode = ExtractOperation::createErofsNode(eo->iter_path, typeId, &inode); LOGCD("type=%s dataLayout=%s %s %s", - eNode->getTypeIdCStr(), - eNode->getDataLayoutCStr(), - eNode->getFsConfig().c_str(), - eNode->getSelinuxLabel().c_str() + eNode->getTypeIdCStr(), + eNode->getDataLayoutCStr(), + eNode->getFsConfig().c_str(), + eNode->getSelinuxLabel().c_str() ); #endif } @@ -120,8 +118,8 @@ namespace skkk { int ret; struct erofs_inode inode = { - .sbi = &g_sbi, - .nid = nid + .sbi = &g_sbi, + .nid = nid }; ret = erofs_read_inode_from_disk(&inode); @@ -133,14 +131,14 @@ namespace skkk { { struct erofs_dir_context ctx = { - .dir = &inode, - .cb = dirent_iter + .dir = &inode, + .cb = dirent_iter }; if (S_ISDIR(inode.i_mode)) { ret = erofs_iterate_dir(&ctx, false); } } -out: + out: return ret; } @@ -155,8 +153,8 @@ namespace skkk { bool ret = 0; char pathnameBuf[PATH_MAX] = {0}; struct erofs_inode vi = { - .sbi = &g_sbi, - .nid = g_sbi.root_nid + .sbi = &g_sbi, + .nid = g_sbi.root_nid }; ret = erofs_ilookup(path.c_str(), &vi); @@ -179,7 +177,7 @@ namespace skkk { } else { createErofsNode(vi); } -out: + out: return ret; } @@ -193,7 +191,7 @@ namespace skkk { */ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd) { struct erofs_map_blocks map = { - .index = UINT_MAX, + .index = UINT_MAX, }; int ret = 0; bool compressed; @@ -254,7 +252,7 @@ namespace skkk { } if (alloc_rawsize > raw_size) { - char *newraw = (char *) realloc(raw, alloc_rawsize); + char *newraw = static_cast(realloc(raw, alloc_rawsize)); if (!newraw) { ret = -ENOMEM; @@ -301,14 +299,14 @@ namespace skkk { } } -out: + out: if (raw) free(raw); if (buffer) free(buffer); return ret < 0 ? ret : 0; -fail_eio: + fail_eio: ret = -EIO; goto out; } @@ -323,7 +321,7 @@ namespace skkk { int erofs_extract_dir(const char *dirPath) { bool tryagain = true; -again: + again: if (mkdirs(dirPath, 0700) < 0) { struct stat st = {}; if (eo->overwrite && tryagain) { @@ -361,7 +359,7 @@ namespace skkk { bool tryagain = true; int ret, fd; -again: + again: fd = open(filePath, O_WRONLY | O_CREAT | O_NOFOLLOW | (eo->overwrite ? O_TRUNC : O_EXCL), 0700); @@ -372,7 +370,7 @@ namespace skkk { return -EISDIR; } } else if (errno == EACCES && - chmod(filePath, 0700) < 0) { + chmod(filePath, 0700) < 0) { return -errno; } tryagain = false; @@ -392,7 +390,6 @@ namespace skkk { if (close(fd)) return -errno; return ret; - } #if defined(_WIN32) || defined(__CYGWIN__) @@ -410,10 +407,7 @@ namespace skkk { return -1; } - if (!CharsetConvert("UTF-8", - "UTF-16LE", - from, strlen(from), - utf16LEBuf, &utf16Len)) { + if (!CharsetConvert("UTF-8", "UTF-16LE", from, strlen(from), utf16LEBuf, &utf16Len)) { return -1; } @@ -439,9 +433,8 @@ namespace skkk { int erofs_extract_symlink(erofs_inode *inode, const char *filePath) { bool tryagain = true; int ret; - char *buf; - buf = (char *) malloc(inode->i_size + 1); + char *buf = static_cast(malloc(inode->i_size + 1)); if (!buf) { ret = -ENOMEM; goto out; @@ -453,7 +446,7 @@ namespace skkk { } buf[inode->i_size] = '\0'; -again: + again: #if !(defined(_WIN32) || defined(__CYGWIN__)) if (symlink(buf, filePath) < 0) { #else @@ -472,7 +465,7 @@ namespace skkk { } ret = -errno; } -out: + out: if (buf) free(buf); return ret; @@ -491,7 +484,7 @@ namespace skkk { if (!fileExists(srcPath)) ret = erofs_extract_file(inode, srcPath); -again: + again: if (strncmp(srcPath, targetPath, strlen(targetPath)) != 0 && #if !(defined(_WIN32) || defined(__CYGWIN__)) link(srcPath, targetPath) < 0) { @@ -511,7 +504,7 @@ namespace skkk { } ret = -errno; } -out: + out: return ret; } @@ -524,11 +517,10 @@ namespace skkk { * @return */ int erofs_extract_special(erofs_inode *inode, const char *filePath) { - bool tryagain = true; int ret = 0; -again: + again: if (mknod(filePath, inode->i_mode, inode->u.i_rdev) < 0) { if (errno == EEXIST && eo->overwrite && tryagain) { if (unlink(filePath) < 0) { @@ -560,18 +552,18 @@ namespace skkk { #ifdef HAVE_UTIMENSAT if (utimensat(AT_FDCWD, path, (struct timespec[]) { { - .tv_sec = (time_t) inode->i_mtime, - .tv_nsec = (time_t) inode->i_mtime_nsec + .tv_sec = static_cast(inode->i_mtime), + .tv_nsec = static_cast(inode->i_mtime_nsec) }, { - .tv_sec = (time_t) inode->i_mtime, - .tv_nsec = (time_t) inode->i_mtime_nsec + .tv_sec = static_cast(inode->i_mtime), + .tv_nsec = static_cast(inode->i_mtime_nsec) }, }, AT_SYMLINK_NOFOLLOW) < 0) #else struct utimbuf ub = { - .actime = (time_t) inode->i_mtime, - .modtime = (time_t) inode->i_mtime + .actime = static_cast(inode->i_mtime), + .modtime = static_cast(inode->i_mtime) }; if (utime(path, &ub) < 0) #endif @@ -599,9 +591,8 @@ namespace skkk { string _tmp = outDir + eNode->getPath(); const char *filePath = _tmp.c_str(); erofs_inode *inode = eNode->getErofsInode(); - const char *hardlinkSrcPath; - hardlinkSrcPath = erofsHardlinkFind(inode->nid); + const char *hardlinkSrcPath = erofsHardlinkFind(inode->nid); if (hardlinkSrcPath) { unique_lock lock(erofsHardlinkLock); return erofs_extract_hardlink(inode, (outDir + hardlinkSrcPath).c_str(), filePath); @@ -642,20 +633,20 @@ namespace skkk { len = erofs_getxattr(inode, XATTR_NAME_CAPABILITY, buf, 128); if (len > 0) { uint64_t capabilities = 0; - auto *fileCapData = (struct vfs_cap_data *) buf; + auto *fileCapData = reinterpret_cast(buf); uint32_t cap_version = le32_to_cpu(fileCapData->magic_etc) & VFS_CAP_REVISION_MASK; // check version size switch (cap_version) { case VFS_CAP_REVISION_1: if (len != XATTR_CAPS_SZ_1) return; - capabilities = le32_to_cpu(fileCapData->data[0].permitted); + capabilities = le64_to_cpu(fileCapData->data[0].permitted); break; case VFS_CAP_REVISION_2: if (len != XATTR_CAPS_SZ_2) return; - capabilities = (uint64_t) le32_to_cpu(fileCapData->data[0].permitted) | - ((uint64_t) le32_to_cpu(fileCapData->data[1].permitted)) << 32; + capabilities = le64_to_cpu(fileCapData->data[0].permitted) | + le64_to_cpu(fileCapData->data[1].permitted) << 32; break; default: return; @@ -734,7 +725,7 @@ namespace skkk { } rc = RET_EXTRACT_DONE; -exit: + exit: return rc; } diff --git a/extract/ExtractOperation.cpp b/extract/ExtractOperation.cpp index 9883f1f2..26f535ff 100644 --- a/extract/ExtractOperation.cpp +++ b/extract/ExtractOperation.cpp @@ -10,7 +10,6 @@ #include "threadpool.h" namespace skkk { - void ExtractOperation::setImgPath(const char *path) { imgPath = path; strTrim(imgPath); @@ -31,8 +30,7 @@ namespace skkk { } void ExtractOperation::erofsOperationExit() { - for_each(erofsNodes.begin(), erofsNodes.end(), - [](auto *eNode) { delete eNode; }); + ranges::for_each(erofsNodes, [](const auto *eNode) { delete eNode; }); erofsNodes.clear(); nodeDirs.clear(); nodeOther.clear(); @@ -132,8 +130,7 @@ namespace skkk { } int ExtractOperation::initErofsNodeAuto() const { - return targetPath.empty() ? - initErofsNodeByRoot() : initErofsNodeByTargetPath(targetPath); + return targetPath.empty() ? initErofsNodeByRoot() : initErofsNodeByTargetPath(targetPath); } const ErofsNode @@ -190,7 +187,7 @@ namespace skkk { } void ExtractOperation::printInitializedNode() { - for_each(erofsNodes.begin(), erofsNodes.end(), printFsConf); + ranges::for_each(erofsNodes, printFsConf); } void ExtractOperation::extractFsConfigAndSelinuxLabelAndFsOptions() const { @@ -256,13 +253,13 @@ namespace skkk { static inline void extractNodeTask(ErofsNode *eNode, const string &outdir) { if (eNode->initExceptionInfo(eNode->writeNodeEntity2File(outdir))) - ExtractOperation::exceptionSize++; + ++ExtractOperation::exceptionSize; } static inline void extractNodeTaskMultiThread(ErofsNode *eNode, const string &outdir) { if (eNode->initExceptionInfo(eNode->writeNodeEntity2File(outdir))) - ExtractOperation::exceptionSize++; - ExtractOperation::extractTaskRunCount++; + ++ExtractOperation::exceptionSize; + ++ExtractOperation::extractTaskRunCount; } static inline void printExtractProgress(int totalSize, int index, int perPrint, bool hasEnter) { diff --git a/extract/include/ErofsHardlinkHandle.h b/extract/include/ErofsHardlinkHandle.h index 2de89c52..62c49b1e 100644 --- a/extract/include/ErofsHardlinkHandle.h +++ b/extract/include/ErofsHardlinkHandle.h @@ -12,16 +12,15 @@ using namespace std; static mutex erofsHardlinkLock; namespace skkk { - class ErofsHardlinkEntry { public: uint64_t nid = 0; string path; + public: ErofsHardlinkEntry() = default; ErofsHardlinkEntry(uint64_t _nid, const char *_path); - }; inline static unordered_map erofsHardlinkMap; @@ -31,7 +30,6 @@ namespace skkk { const char *erofsHardlinkFind(uint64_t nid); void erofsHardlinkExit(); - } #endif // EXTRACT_EROFS_HARDLINK_HANDLE_H diff --git a/extract/include/ErofsNode.h b/extract/include/ErofsNode.h index 1d28dd2a..81f68a6a 100644 --- a/extract/include/ErofsNode.h +++ b/extract/include/ErofsNode.h @@ -10,7 +10,6 @@ using namespace std; namespace skkk { - static inline void handleSpecialSymbols(string &str) { strReplaceAll(str, ".", "\\."); strReplaceAll(str, "+", "\\+"); @@ -19,7 +18,7 @@ namespace skkk { } static set otherPathsInRootDir = { - "/lost+found" + "/lost+found" }; /** @@ -80,10 +79,9 @@ namespace skkk { void writeSelinuxLabel2File(FILE *selinuxLabelsFile, const char *mountPoint) const; - int writeNodeEntity2File(const string &outDir); + int writeNodeEntity2File(const string &outDir) const; void writeExceptionInfo2FileIfExists(FILE *infoFile) const; - }; } #endif //EXTRACT_EROFS_NODE_H diff --git a/extract/include/ExtractHelper.h b/extract/include/ExtractHelper.h index 71fd3cb5..b97a44a1 100644 --- a/extract/include/ExtractHelper.h +++ b/extract/include/ExtractHelper.h @@ -17,7 +17,6 @@ using namespace std; #endif namespace skkk { - /** * erofs_extract_dir * Copy from fsck.erofs @@ -119,7 +118,6 @@ namespace skkk { * @return */ int initErofsNodeByTargetConfig(const string &targetPath, bool recursive = false); - } #endif //EXTRACT_HELPER_H diff --git a/extract/include/Utils.h b/extract/include/Utils.h index af649434..ecbda6a1 100644 --- a/extract/include/Utils.h +++ b/extract/include/Utils.h @@ -96,7 +96,7 @@ static inline bool CharsetConvert(const char *fromCharset, const char *toCharset const char *input, size_t inputLen, const char *output, size_t *outputLen) { bool ret = false; iconv_t conv = iconv_open(toCharset, fromCharset); - if (conv != (iconv_t) -1) { + if (conv != reinterpret_cast(-1)) { char *_input = const_cast(input); char *_output = const_cast(output); if (iconv(conv, &_input, &inputLen, &_output, outputLen) != -1) { diff --git a/extract/main.cpp b/extract/main.cpp index 3fa9d5be..9b75ae5a 100644 --- a/extract/main.cpp +++ b/extract/main.cpp @@ -63,23 +63,23 @@ static inline void print_version() { string compressors; get_available_compressors(compressors); printf(" " BROWN "erofs-utils:" COLOR_NONE " " RED2_BOLD "%s" COLOR_NONE "\n", cfg.c_version); - printf(" " BROWN "extract.erofs:" COLOR_NONE " " RED2_BOLD "1.0.5" COLOR_NONE "\n"); + printf(" " BROWN "extract.erofs:" COLOR_NONE " " RED2_BOLD "1.0.6" COLOR_NONE "\n"); printf(" " BROWN "Available compressors:" COLOR_NONE " " RED2_BOLD "%s" COLOR_NONE "\n", compressors.c_str()); printf(" " BROWN "extract author:" COLOR_NONE " " RED2_BOLD "skkk" COLOR_NONE "\n"); } static struct option arg_options[] = { - {"help", no_argument, nullptr, 'h'}, - {"version", no_argument, nullptr, 'V'}, - {"image", required_argument, nullptr, 'i'}, - {"offset", required_argument, nullptr, 2}, - {"outdir", required_argument, nullptr, 'o'}, - {"print", required_argument, nullptr, 'P'}, - {"overwrite", no_argument, nullptr, 'f'}, - {"extract", required_argument, nullptr, 'X'}, - {"config", required_argument, nullptr, 'c'}, - {"only-cfg", no_argument, nullptr, 1}, - {nullptr, no_argument, nullptr, 0}, + {"help", no_argument, nullptr, 'h'}, + {"version", no_argument, nullptr, 'V'}, + {"image", required_argument, nullptr, 'i'}, + {"offset", required_argument, nullptr, 2}, + {"outdir", required_argument, nullptr, 'o'}, + {"print", required_argument, nullptr, 'P'}, + {"overwrite", no_argument, nullptr, 'f'}, + {"extract", required_argument, nullptr, 'X'}, + {"config", required_argument, nullptr, 'c'}, + {"only-cfg", no_argument, nullptr, 1}, + {nullptr, no_argument, nullptr, 0}, }; static int parseAndCheckExtractCfg(int argc, char **argv) { @@ -210,7 +210,7 @@ static int parseAndCheckExtractCfg(int argc, char **argv) { static inline void printOperationTime(struct timeval *start, struct timeval *end) { LOGCI(GREEN2_BOLD "The operation took: " COLOR_NONE RED2 "%.3f" COLOR_NONE "%s", - (end->tv_sec - start->tv_sec) + (float) (end->tv_usec - start->tv_usec) / 1000000, + (end->tv_sec - start->tv_sec) + static_cast(end->tv_usec - start->tv_usec) / 1000000, GREEN2_BOLD " second(s)." COLOR_NONE ); }