mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-09-13 13:05:23 -05:00
File mode somewhat working.
This commit is contained in:
@@ -3,23 +3,40 @@
|
||||
#include "error.hpp"
|
||||
#include "fs/fs.hpp"
|
||||
#include "fslib.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
|
||||
void tasks::fileoptions::copy_source_to_destination(sys::ProgressTask *task, FileOptionState::TaskData taskData)
|
||||
{
|
||||
if (error::is_null(task)) { return; }
|
||||
|
||||
fslib::Path &source = taskData->sourcePath;
|
||||
fslib::Path &dest = taskData->destPath;
|
||||
int64_t journalSpace = taskData->journalSize;
|
||||
const fslib::Path &source = taskData->sourcePath;
|
||||
const fslib::Path &dest = taskData->destPath;
|
||||
const int64_t journalSpace = taskData->journalSize;
|
||||
FileOptionState *spawningState = taskData->spawningState;
|
||||
|
||||
const bool sourceIsDir = fslib::directory_exists(source);
|
||||
bool destError = false;
|
||||
if (sourceIsDir) { destError = error::fslib(fslib::create_directories_recursively(dest)); }
|
||||
else
|
||||
{
|
||||
const size_t subDest = dest.find_last_of('/');
|
||||
if (subDest != dest.NOT_FOUND && subDest > 1)
|
||||
{
|
||||
fslib::Path subDestPath{dest.sub_path(subDest)};
|
||||
destError = error::fslib(fslib::create_directories_recursively(subDestPath));
|
||||
}
|
||||
}
|
||||
|
||||
if (destError) { TASK_FINISH_RETURN(task); }
|
||||
|
||||
const bool isDir = fslib::directory_exists(source);
|
||||
const bool needsCommit = journalSpace > 0;
|
||||
|
||||
if (isDir && needsCommit) { fs::copy_directory_commit(source, dest, journalSpace, task); }
|
||||
else if (!isDir && needsCommit) { fs::copy_file_commit(source, dest, journalSpace, task); }
|
||||
else if (isDir && !needsCommit) { fs::copy_directory(source, dest, task); }
|
||||
else if (!isDir && !needsCommit) { fs::copy_file(source, dest, task); }
|
||||
if (sourceIsDir && needsCommit) { fs::copy_directory_commit(source, dest, journalSpace, task); }
|
||||
else if (!sourceIsDir && needsCommit) { fs::copy_file_commit(source, dest, journalSpace, task); }
|
||||
else if (sourceIsDir && !needsCommit) { fs::copy_directory(source, dest, task); }
|
||||
else if (!sourceIsDir && !needsCommit) { fs::copy_file(source, dest, task); }
|
||||
|
||||
spawningState->update_destination();
|
||||
task->complete();
|
||||
}
|
||||
|
||||
@@ -27,8 +44,9 @@ void tasks::fileoptions::delete_target(sys::Task *task, FileOptionState::TaskDat
|
||||
{
|
||||
if (error::is_null(task)) { return; }
|
||||
|
||||
fslib::Path target = taskData->sourcePath;
|
||||
int64_t journalSpace = taskData->journalSize;
|
||||
fslib::Path target = taskData->sourcePath;
|
||||
int64_t journalSpace = taskData->journalSize;
|
||||
FileOptionState *spawningState = taskData->spawningState;
|
||||
|
||||
const bool isDir = fslib::directory_exists(target);
|
||||
bool needsCommit = journalSpace > 0;
|
||||
@@ -38,5 +56,6 @@ void tasks::fileoptions::delete_target(sys::Task *task, FileOptionState::TaskDat
|
||||
|
||||
if (needsCommit) { fslib::commit_data_to_file_system(target.get_device_name()); }
|
||||
|
||||
spawningState->update_source();
|
||||
task->complete();
|
||||
}
|
||||
Reference in New Issue
Block a user