From ba78223c0c3ee22f3417e498bfa9da1154efc7fc Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Wed, 22 Feb 2023 03:27:49 +0100 Subject: [PATCH] Fix #48: Redirect compression execution logs for not having them overlapping `PRINT`s --- main.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index e78f501..1535608 100644 --- a/main.cpp +++ b/main.cpp @@ -60,7 +60,8 @@ string CHANNELS_DIRECTORY = "channels/", YOUTUBE_OPERATIONAL_API_INSTANCE_URL = "http://localhost/YouTube-operational-API", // Can be "https://yt.lemnoslife.com" for instance. CAPTIONS_DIRECTORY = "captions/", DEBUG_DIRECTORY = "debug/", - YOUTUBE_API_REQUESTS_DIRECTORY = "requests/"; + YOUTUBE_API_REQUESTS_DIRECTORY = "requests/", + CURRENT_WORKING_DIRECTORY; bool USE_YT_LEMNOSLIFE_COM_NO_KEY_SERVICE = false; int main(int argc, char *argv[]) @@ -129,6 +130,13 @@ int main(int argc, char *argv[]) } } + char cwd[PATH_MAX]; + if (getcwd(cwd, sizeof(cwd)) != NULL) { + CURRENT_WORKING_DIRECTORY = string(cwd) + "/"; + } else { + MAIN_EXIT_WITH_ERROR("`getcwd()` error"); + } + MAIN_PRINT(channelsToTreat.size() << " channel(s) to treat") MAIN_PRINT(channelsAlreadyTreated.size() << " channel(s) already treated") @@ -194,13 +202,13 @@ void treatChannels(unsigned short threadId) // As I haven't found any well-known library that compress easily a directory, I have chosen to rely on `zip` cli. // We precise no `debug`ging, as otherwise the zipping operation doesn't work as expected. // As the zipping process isn't recursive, we can't just rely on `ls`, but we are obliged to use `find`. - exec(threadId, "cd " + channelToTreatDirectory + " && find | zip ../" + channelToTreat + ".zip -@", false); + exec(threadId, "cd " + channelToTreatDirectory + " && find | zip ../" + channelToTreat + ".zip -@"); PRINT("Compression finished, started deleting initial directory...") deleteDirectory(channelToTreatDirectory); PRINT("Deleting directory finished.") - PRINT(channelsCountThreads[threadId] << " comments were found for this channel.") + PRINT(channelsCountThreads[threadId] << " channels were found for this channel.") } channelsAlreadyTreatedAndToTreatMutex.unlock(); @@ -671,7 +679,7 @@ void exec(unsigned short threadId, string cmd, bool debug) toString << threadId; string initialCmd = cmd, threadIdStr = toString.str(), - debugCommonFilePath = DEBUG_DIRECTORY + threadIdStr, + debugCommonFilePath = CURRENT_WORKING_DIRECTORY + DEBUG_DIRECTORY + threadIdStr, debugOutFilePath = debugCommonFilePath + ".out", debugErrFilePath = debugCommonFilePath + ".err"; cmd += " >> " + debugOutFilePath;