Commit d33334a3 authored by Matthieu Dorier's avatar Matthieu Dorier

added mode support

parent ed886341
......@@ -128,6 +128,7 @@ extern "C" int remi_fileset_migrate(
// expose the data
std::vector<std::pair<void*,std::size_t>> theData;
std::vector<std::size_t> theSizes;
std::vector<mode_t> theModes;
// prepare lambda for cleaning up mapped files
auto cleanup = [&theData]() {
......@@ -160,6 +161,8 @@ extern "C" int remi_fileset_migrate(
}
auto size = st.st_size;
theSizes.push_back(size);
auto mode = st.st_mode;
theModes.push_back(mode);
if(size == 0) {
close(fd);
continue;
......@@ -191,7 +194,7 @@ extern "C" int remi_fileset_migrate(
fileset->m_root = theRemoteRoot;
// send the RPC
std::pair<int32_t, int32_t> result = ph->m_client->m_migrate_rpc.on(*ph)(*fileset, theSizes, localBulk);
std::pair<int32_t, int32_t> result = ph->m_client->m_migrate_rpc.on(*ph)(*fileset, theSizes, theModes, localBulk);
int ret = result.first;
*status = result.second;
......
......@@ -40,6 +40,7 @@ struct remi_provider : public tl::provider<remi_provider> {
const tl::request& req,
remi_fileset& fileset,
const std::vector<std::size_t>& filesizes,
const std::vector<mode_t>& theModes,
tl::bulk& remote_bulk)
{
// pair of <returnvalue, status>
......@@ -93,7 +94,7 @@ struct remi_provider : public tl::provider<remi_provider> {
auto theDir = theFilename.substr(0, p);
mkdirs(theDir.c_str());
totalSize += filesizes[i];
int fd = open(theFilename.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0600);
int fd = open(theFilename.c_str(), O_RDWR | O_CREAT | O_TRUNC, theModes[i]);
if(fd == -1) {
cleanup();
result.first = REMI_ERR_IO;
......@@ -112,8 +113,8 @@ struct remi_provider : public tl::provider<remi_provider> {
return;
}
void *segment = mmap(0, filesizes[i], PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
close(fd);
if(segment == NULL) {
close(fd);
cleanup();
result.first = REMI_ERR_IO;
req.respond(result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment