18 std::unique_ptr<ioHandle::attrDataType>,
19 std::unique_ptr<acl::list>) {
20 return std::unique_ptr<base::writer>(
new writerDavix(*
this, path,
36 const std::string& srcPath,
38 std::vector<std::remove_reference<decltype(path)>::type::value_type> disposable_buffer(path.c_str(), path.c_str() + path.size() + 1);
39 std::string dir(dirname(disposable_buffer.data()));
42 if (
posix.stat(&
params, dir, &statbuf, report) != 0) {
43 if (report->getStatus() == Davix::StatusCode::FileNotFound) {
46 if (
posix.mkdir(&
params, dir, 0777u, report2) != 0) {
47 if (report2->getStatus() == Davix::StatusCode::FileExist) {
55 }
else if (! S_ISDIR(statbuf.st_mode)) {
57 dir,
"ensure parents",
58 "is not a directory (st_mode is ", statbuf.st_mode,
") but should be");
67 if (
posix.stat(&
params, path, &dsttat, report) != 0) {
68 if (report->getStatus() == Davix::StatusCode::FileNotFound) {
75 if (S_ISDIR(dsttat.st_mode)) {
77 if (
posix.rmdir(
nullptr, path, report) != 0) {
78 if (report->getStatus() == Davix::StatusCode::FileNotFound) {
81 }
else if (report->getStatus() == Davix::StatusCode::FileExist) {
94 if (report->getStatus() == Davix::StatusCode::FileNotFound) {
106 const std::string& toPath) {
111 if (report->getStatus() != Davix::StatusCode::FileNotFound) {
118 if (
posix.rename(&
params, fromPath, toPath, report)) {
119 if (report->getStatus() == Davix::StatusCode::FileNotFound) {
129 const std::unique_ptr<const genericStat>& ,
138 const std::string& aPath,
145 auto openMode = O_CREAT | O_WRONLY;
156 if (handler.posix.close(fd, report) != 0) {
158 path,
"close during unwind ",
163 path,
"unlink failed copy",
"due to exception");
164 if (handler.posix.unlink(&handler.params, path, report) != 0) {
171 closeAndRemoveBadCopy();
175 if (handler.posix.close(fd, report) != 0) {
183 size_t bytes_writen_so_far = 0;
185 while (bytes_writen_so_far < b.
size()) {
187 auto count = b.
size() - bytes_writen_so_far;
192 count = std::min(count, blockSize);
195 auto bytes_writen = handler.posix.write(fd, b.
bufferAt(bytes_writen_so_far), count, report);
196 if (bytes_writen < 0) {
201 bytes_writen_so_far += bytes_writen;
212 throw std::runtime_error(
"sync not supported");