Skip to content

Commit 9c52d0f

Browse files
committed
modified �compressAndDownload section
1 parent 19d80b1 commit 9c52d0f

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/operations.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,20 @@ void startJob(){
310310

311311
const std::wstring shellType {L"/bin/sh"};
312312
std::wstring archivePath = path;
313+
std::wstring filename = extractFilename(path);
313314
if((archivePath.back() == L'/') || (archivePath.back() == L'\\')){
314315
archivePath.pop_back();
315-
}
316+
}
316317
const std::wstring compressionTool {L"tar"};
317-
const std::wstring args {L"-czf " + std::wstring(L"\"") + archivePath + L".tar.gz\"" + std::wstring(L" -C ") + std::wstring(L"\"") + path + L"\" ."};
318+
std::wstring args {L"-czf " + std::wstring(L"\"") + archivePath + L".tar.gz\""};
319+
if(fs::is_directory(path)){
320+
// For directory --> tar -czf "archivePath.tar.gz" -C "path/to/dir" .
321+
args += std::wstring(L" -C ") + std::wstring(L"\"") + path + L"\" .";
322+
}
323+
else{
324+
// For file --> tar -czf "path/to/dir/file.tar.gz" -C "path/to/dir" "filename"
325+
args += std::wstring(L" -C \"") + archivePath.substr(0, archivePath.size()-filename.size()) + std::wstring(L"\" \"") + filename + L"\"";
326+
}
318327
const std::wstring output = executeCommand(shellType, compressionTool, args); // Archive/Compress it
319328
archivePath.append(L".tar.gz");
320329
if(output.find(L"status: 0") != std::wstring::npos){

0 commit comments

Comments
 (0)