Skip to content

Commit

Permalink
Use custom copyDirectory instead of libc++fs
Browse files Browse the repository at this point in the history
libc++fs isn’t alway available
  • Loading branch information
matthewbauer committed Jun 1, 2020
1 parent eb90cc6 commit b120259
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/libutil/fs-sink.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <fcntl.h>
#include <filesystem>

#include "types.hh"
#include "serialise.hh"
Expand Down Expand Up @@ -95,7 +94,20 @@ struct RestoreSink : ParseSink
void copyDirectory(const Path & source, const Path & destination)
{
Path p = dstPath + destination;
std::filesystem::copy(source, p);
createDirectory(destination);
for (auto & i : readDirectory(source)) {
struct stat st;
Path entry = source + "/" + i.name;
if (lstat(entry.c_str(), &st))
throw SysError(format("getting attributes of path '%1%'") % entry);
if (S_ISREG(st.st_mode)) {
createRegularFile(destination + "/" + i.name);
copyFile(entry);
} else if (S_ISDIR(st.st_mode))
copyDirectory(entry, destination + "/" + i.name);
else
throw Error(format("Unknown file: %s") % entry);
}
}
};

Expand Down
1 change: 0 additions & 1 deletion src/libutil/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ static void parse(ParseSink & sink, Source & source, const Path & path, const Pa
if (perm != 40000)
throw SysError(format("file is a directory but expected to be a file '%1%'") % entry);

sink.createDirectory(path + "/" + name);
sink.copyDirectory(realStoreDir + "/" + entryName, path + "/" + name);
} else throw Error(format("file '%1%' has an unsupported type") % entry);
}
Expand Down

0 comments on commit b120259

Please sign in to comment.