Skip to content

Commit c03fd26

Browse files
committed
Filesystem fixes
1 parent d2f7837 commit c03fd26

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

examples_tests/52.SystemTest/main.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,18 @@ int main(int argc, char** argv)
306306
}
307307
};
308308

309-
auto tarArch = system->openFileArchive(CWD.generic_string() + "file.tar");
310-
system->mount(std::move(tarArch), "tarArch");
311309
auto arch = system->openFileArchive(CWD.generic_string() + "test.zip");
312310
system->mount(std::move(arch), "arch");
313-
auto arch1 = system->openFileArchive("arch/test/test1.zip");
314-
system->mount(std::move(arch1), "arch1");
311+
auto bigarch = system->openFileArchive(CWD.generic_string() + "../../media/sponza.zip");
312+
system->mount(std::move(bigarch), "sponza");
313+
314+
system->copy(CWD.generic_string() + "pngWriteSuccessful.png", "pngCopy.png");
315+
316+
system->createDirectory(CWD.generic_string() + "textures1");
317+
system->copy(CWD.generic_string() + "textures", CWD.generic_string() + "textures1");
318+
system->copy("sponza/textures", CWD.generic_string() + "textures");
319+
system->moveFileOrDirectory("file.tar", "movedFile.tar");
320+
system->listFilesInDirectory(CWD.generic_string() + "textures");
315321
{
316322
system::future<smart_refctd_ptr<IFile>> fut;
317323
system->createFile(fut, "tarArch/file.txt", IFile::ECF_READ);

include/nbl/system/IFile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class future;
1818
class IFile : public core::IReferenceCounted
1919
{
2020
friend class ISystemCaller;
21+
friend class ISystem;
2122
friend class IFileArchive;
2223
public:
2324
enum E_CREATE_FLAGS : uint32_t

include/nbl/system/ISystem.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,20 @@ class ISystem : public core::IReferenceCounted
366366

367367
bool createDirectory(const system::path& p)
368368
{
369-
return std::filesystem::create_directory(p);
369+
return std::filesystem::create_directories(p);
370370
}
371371

372372
bool deleteDirectory(const system::path& p)
373373
{
374374
return std::filesystem::remove(p);
375375
}
376376

377-
377+
bool moveFileOrDirectory(const system::path oldPath, const system::path newPath)
378+
{
379+
std::error_code ec;
380+
std::filesystem::rename(oldPath, newPath, ec);
381+
return static_cast<bool>(ec);
382+
}
378383
/*
379384
Recursively lists all files and directories in the directory.
380385
*/
@@ -431,22 +436,19 @@ class ISystem : public core::IReferenceCounted
431436
*/
432437
bool copy(const system::path& from, const system::path& to)
433438
{
434-
constexpr auto copyFile = [this](const system::path& from, const system::path& to)
439+
auto copyFile = [this](const system::path& from, const system::path& to)
435440
{
436-
system::future<core::smart_refctd_ptr<IFile>> readFileFut, writeFileFut;
437-
system::future<size_t> readFut, writeFut;
441+
future_t<core::smart_refctd_ptr<IFile>> readFileFut, writeFileFut;
438442

439443
createFile(readFileFut, from, IFile::ECF_READ);
440-
createFile(writeFileFut, from, IFile::ECF_WRITE);
441-
auto readFile = readFileFut.get();
442-
auto writeFile = writeFileFut.get();
444+
createFile(writeFileFut, to, IFile::ECF_WRITE);
445+
auto readF = readFileFut.get();
446+
auto writeF = writeFileFut.get();
443447

444-
char* fileData = (char*)malloc(readFile->getSize());
445-
readFile->read(readFut, fileData, 0, readFile->getSize());
446-
readFut.get();
448+
char* fileData = (char*)malloc(readF->getSize());
449+
readF->read_impl(fileData, 0, readF->getSize());
447450

448-
writeFile->write(writeFut, fileData, 0, readFile->getSize());
449-
writeFut.get();
451+
writeF->write_impl(fileData, 0, readF->getSize());
450452

451453
free(fileData);
452454
};
@@ -459,8 +461,12 @@ class ISystem : public core::IReferenceCounted
459461
for (const auto& file : allFiles)
460462
{
461463
auto relative = std::filesystem::relative(file, from);
462-
auto targetName = to / relative;
463-
copyFile(file, targetName);
464+
system::path targetName = (to / relative).generic_string();
465+
std::filesystem::create_directories(targetName.parent_path());
466+
if (!isDirectory(targetName))
467+
{
468+
copyFile(file, targetName);
469+
}
464470
}
465471
}
466472
else

0 commit comments

Comments
 (0)