File mode somewhat working.

This commit is contained in:
J-D-K
2025-09-04 15:34:43 -04:00
parent a072c28dfb
commit 828050c1b9
85 changed files with 690 additions and 572 deletions

View File

@@ -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();
}