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( ...@@ -128,6 +128,7 @@ extern "C" int remi_fileset_migrate(
// expose the data // expose the data
std::vector<std::pair<void*,std::size_t>> theData; std::vector<std::pair<void*,std::size_t>> theData;
std::vector<std::size_t> theSizes; std::vector<std::size_t> theSizes;
std::vector<mode_t> theModes;
// prepare lambda for cleaning up mapped files // prepare lambda for cleaning up mapped files
auto cleanup = [&theData]() { auto cleanup = [&theData]() {
...@@ -160,6 +161,8 @@ extern "C" int remi_fileset_migrate( ...@@ -160,6 +161,8 @@ extern "C" int remi_fileset_migrate(
} }
auto size = st.st_size; auto size = st.st_size;
theSizes.push_back(size); theSizes.push_back(size);
auto mode = st.st_mode;
theModes.push_back(mode);
if(size == 0) { if(size == 0) {
close(fd); close(fd);
continue; continue;
...@@ -191,7 +194,7 @@ extern "C" int remi_fileset_migrate( ...@@ -191,7 +194,7 @@ extern "C" int remi_fileset_migrate(
fileset->m_root = theRemoteRoot; fileset->m_root = theRemoteRoot;
// send the RPC // 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; int ret = result.first;
*status = result.second; *status = result.second;
......
...@@ -40,6 +40,7 @@ struct remi_provider : public tl::provider<remi_provider> { ...@@ -40,6 +40,7 @@ struct remi_provider : public tl::provider<remi_provider> {
const tl::request& req, const tl::request& req,
remi_fileset& fileset, remi_fileset& fileset,
const std::vector<std::size_t>& filesizes, const std::vector<std::size_t>& filesizes,
const std::vector<mode_t>& theModes,
tl::bulk& remote_bulk) tl::bulk& remote_bulk)
{ {
// pair of <returnvalue, status> // pair of <returnvalue, status>
...@@ -93,7 +94,7 @@ struct remi_provider : public tl::provider<remi_provider> { ...@@ -93,7 +94,7 @@ struct remi_provider : public tl::provider<remi_provider> {
auto theDir = theFilename.substr(0, p); auto theDir = theFilename.substr(0, p);
mkdirs(theDir.c_str()); mkdirs(theDir.c_str());
totalSize += filesizes[i]; 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) { if(fd == -1) {
cleanup(); cleanup();
result.first = REMI_ERR_IO; result.first = REMI_ERR_IO;
...@@ -112,8 +113,8 @@ struct remi_provider : public tl::provider<remi_provider> { ...@@ -112,8 +113,8 @@ struct remi_provider : public tl::provider<remi_provider> {
return; return;
} }
void *segment = mmap(0, filesizes[i], PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0); void *segment = mmap(0, filesizes[i], PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
close(fd);
if(segment == NULL) { if(segment == NULL) {
close(fd);
cleanup(); cleanup();
result.first = REMI_ERR_IO; result.first = REMI_ERR_IO;
req.respond(result); 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