mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 17:37:36 +03:00
Automatically creates the destination folder if it does not exist
This commit is contained in:
parent
0cf770017d
commit
71caa3356c
2 changed files with 33 additions and 7 deletions
|
@ -1907,8 +1907,12 @@ static int owncloud_rename(const char *olduri, const char *newuri) {
|
|||
if( rc >= 0 ) {
|
||||
DEBUG_WEBDAV("MOVE: %s => %s: %d", src, target, rc );
|
||||
rc = ne_move(dav_session.ctx, 1, src, target );
|
||||
|
||||
set_errno_from_neon_errcode(rc);
|
||||
if (rc == NE_ERROR && http_result_code_from_session() == 409) {
|
||||
/* destination folder might not exist */
|
||||
errno = ENOENT;
|
||||
} else {
|
||||
set_errno_from_neon_errcode(rc);
|
||||
}
|
||||
}
|
||||
SAFE_FREE( src );
|
||||
SAFE_FREE( target );
|
||||
|
|
|
@ -694,6 +694,7 @@ static int _csync_rename_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
char *duri = NULL;
|
||||
const char *tmd5 = NULL;
|
||||
c_rbnode_t *node = NULL;
|
||||
char *tdir = NULL;
|
||||
|
||||
switch (ctx->current) {
|
||||
case REMOTE_REPLICA:
|
||||
|
@ -719,21 +720,41 @@ static int _csync_rename_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
}
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Renaming %s => %s", suri, duri);
|
||||
|
||||
if (! c_streq(suri, duri)) {
|
||||
if (rc > -1 && (rc = csync_vio_rename(ctx, suri, duri)) != 0) {
|
||||
if (! c_streq(suri, duri) && rc > -1) {
|
||||
while ((rc = csync_vio_rename(ctx, suri, duri)) != 0) {
|
||||
switch (errno) {
|
||||
case ENOENT:
|
||||
/* get the directory name */
|
||||
if(tdir) {
|
||||
/* we're looping */
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN,
|
||||
"dir: %s, loop in mkdir detected!", tdir);
|
||||
rc = 1;
|
||||
goto out;
|
||||
}
|
||||
tdir = c_dirname(duri);
|
||||
if (tdir == NULL) {
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (csync_vio_mkdirs(ctx, tdir, C_DIR_MODE) < 0) {
|
||||
strerror_r(errno, errbuf, sizeof(errbuf));
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN,
|
||||
"dir: %s, command: mkdirs, error: %s",
|
||||
tdir, errbuf);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
strerror_r(errno, errbuf, sizeof(errbuf));
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
|
||||
"dir: %s, command: rename, error: %s",
|
||||
suri,
|
||||
errbuf);
|
||||
break;
|
||||
goto out;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
||||
/* set owner and group if possible */
|
||||
if (ctx->pwd.euid == 0) {
|
||||
csync_vio_chown(ctx, duri, st->uid, st->gid);
|
||||
|
@ -782,6 +803,7 @@ static int _csync_rename_file(CSYNC *ctx, csync_file_stat_t *st) {
|
|||
out:
|
||||
SAFE_FREE(suri);
|
||||
SAFE_FREE(duri);
|
||||
SAFE_FREE(tdir);
|
||||
|
||||
/* set instruction for the statedb merger */
|
||||
if (rc != 0) {
|
||||
|
|
Loading…
Reference in a new issue