File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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){
You can’t perform that action at this time.
0 commit comments