Skip to content

Commit

Permalink
extract: Add silent mode option
Browse files Browse the repository at this point in the history
Signed-off-by: sekaiacg <[email protected]>
  • Loading branch information
sekaiacg committed Jan 26, 2025
1 parent 9b05ab9 commit f391fcc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
24 changes: 13 additions & 11 deletions extract/ExtractOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,20 @@ namespace skkk {
}
}

void ExtractOperation::extractErofsNode() const {
void ExtractOperation::extractErofsNode(bool isSilent) const {
extractNodeDirs();
if (!nodeOther.empty()) {
int nodeOtherSize = nodeOther.size();
for (int i = 0; i < nodeOtherSize; i++) {
extractNodeTask(nodeOther[i], outDir);
printExtractProgress(nodeOtherSize, i + 1, 2, true);
if (!isSilent) printExtractProgress(nodeOtherSize, i + 1, 2, true);
}
}
// If there is an exception
writeExceptionInfo2File();
}

void ExtractOperation::extractErofsNodeMultiThread() const {
void ExtractOperation::extractErofsNodeMultiThread(bool isSilent) const {
extractNodeDirs();
LOGCI(GREEN2_BOLD "Use " COLOR_NONE RED2 "%d" COLOR_NONE GREEN2_BOLD " therads" COLOR_NONE, threadNum);

Expand All @@ -309,16 +309,18 @@ namespace skkk {
tp.commit(extractNodeTaskMultiThread, eNode, outDir);
}

int i = 0;
while (extractTaskRunCount < nodeOtherSize) {
if (i != extractTaskRunCount) {
printExtractProgress(nodeOtherSize, extractTaskRunCount, 1, false);
i = extractTaskRunCount;
if (!isSilent) {
int i = 0;
while (extractTaskRunCount < nodeOtherSize) {
if (i != extractTaskRunCount) {
printExtractProgress(nodeOtherSize, extractTaskRunCount, 1, false);
i = extractTaskRunCount;
}
sleep(0);
}
sleep(0);
printExtractProgress(1, 1, 1, true);
LOGCD("extractTaskRunCount=%d nodeFilesSize=%d", i, nodeOtherSize, nodeOther.size());
}
printExtractProgress(1, 1, 1, true);
LOGCD("extractTaskRunCount=%d nodeFilesSize=%d", i, nodeOtherSize, nodeOther.size());

writeExceptionInfo2File();
}
Expand Down
5 changes: 3 additions & 2 deletions extract/include/ExtractOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ namespace skkk {
string targetPath;
string targetConfigPath;
bool extractOnlyConfAndSeLabel = false;
bool isSilent = false;

public:

Expand Down Expand Up @@ -130,9 +131,9 @@ namespace skkk {

void extractNodeDirs() const;

void extractErofsNode() const;
void extractErofsNode(bool isSilent) const;

void extractErofsNodeMultiThread() const;
void extractErofsNodeMultiThread(bool isSilent) const;
};

/**
Expand Down
9 changes: 7 additions & 2 deletions extract/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static inline void usage() {
" " GREEN2_BOLD "-X, --extract=X" COLOR_NONE " " BROWN "Extract the target of path X" COLOR_NONE "\n"
" " GREEN2_BOLD "-c, --config=[FILE]" COLOR_NONE " " BROWN "Target of config" COLOR_NONE "\n"
" " GREEN2_BOLD "-r" COLOR_NONE " " BROWN "When using config, recurse directories" COLOR_NONE "\n"
" " GREEN2_BOLD "-s" COLOR_NONE " " BROWN "Silent mode, Don't show progress" COLOR_NONE "\n"
" " GREEN2_BOLD "-f, --overwrite" COLOR_NONE " " BROWN "[" GREEN2_BOLD "default: skip" COLOR_NONE BROWN "] overwrite files that already exist" COLOR_NONE "\n"
" " GREEN2_BOLD "-T#" COLOR_NONE " " BROWN "[" GREEN2_BOLD "1-%u" COLOR_NONE BROWN "] Use # threads, -T0: " GREEN2_BOLD "%u" COLOR_NONE COLOR_NONE "\n"
" " GREEN2_BOLD "--only-cfg" COLOR_NONE " " BROWN "Only extract fs_config|file_contexts|fs_options" COLOR_NONE "\n"
Expand Down Expand Up @@ -85,7 +86,7 @@ static int parseAndCheckExtractCfg(int argc, char **argv) {
int opt;
int rc = RET_EXTRACT_CONFIG_FAIL;
bool enterParseOpt = false;
while ((opt = getopt_long(argc, argv, "hi:pxfrc:P:T:o:X:V", arg_options, nullptr)) != -1) {
while ((opt = getopt_long(argc, argv, "hi:psxfrc:P:T:o:X:V", arg_options, nullptr)) != -1) {
enterParseOpt = true;
switch (opt) {
case 'h':
Expand Down Expand Up @@ -135,6 +136,10 @@ static int parseAndCheckExtractCfg(int argc, char **argv) {
if (optarg) eo->targetConfigPath = optarg;
LOGCD("targetConfig=%s", eo->targetConfigPath.c_str());
break;
case 's':
eo->isSilent = true;
LOGCD("isSilent=%d", eo->isSilent);
break;
case 'r':
eo->targetConfigRecurse = true;
LOGCD("targetConfigRecurse=%d", eo->targetConfigRecurse);
Expand Down Expand Up @@ -282,7 +287,7 @@ int main(int argc, char **argv) {
LOGCW("Failed change case sensitive.");
#endif
eo->extractFsConfigAndSelinuxLabelAndFsOptions();
eo->useMultiThread ? eo->extractErofsNodeMultiThread() : eo->extractErofsNode();
eo->useMultiThread ? eo->extractErofsNodeMultiThread(eo->isSilent) : eo->extractErofsNode(eo->isSilent);
goto end;
}

Expand Down

0 comments on commit f391fcc

Please sign in to comment.