Ticket #3917: mc-sftp-amtime.patch
File mc-sftp-amtime.patch, 4.3 KB (added by moko, 6 years ago) |
---|
-
src/vfs/sftpfs/internal.c
Subject: [PATCH] Preserve atime/mtime over sftpfs --- src/vfs/sftpfs/internal.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++ src/vfs/sftpfs/internal.h | 1 + src/vfs/sftpfs/vfs_class.c | 26 ++++++++++++++++----- 3 files changed, 77 insertions(+), 6 deletions(-) diff --git a/src/vfs/sftpfs/internal.c b/src/vfs/sftpfs/internal.c index 443126e95..85d3c83be 100644
a b sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** 419 419 return 0; 420 420 } 421 421 422 /* --------------------------------------------------------------------------------------------- */ 423 /** 424 * Changes the times of the file. 425 * 426 * @param vpath path to file or directory 427 * @param atime access time 428 * @param mtime modification time 429 * @param mcerror pointer to error object 430 * @return 0 if success, negative value otherwise 431 */ 432 433 int 434 sftpfs_utime (const vfs_path_t * vpath,time_t atime, time_t mtime, GError ** mcerror) 435 { 436 sftpfs_super_data_t *super_data = NULL; 437 const vfs_path_element_t *path_element = NULL; 438 LIBSSH2_SFTP_ATTRIBUTES attrs; 439 int res; 440 441 res = sftpfs_stat_init (&super_data, &path_element, vpath, mcerror, LIBSSH2_SFTP_LSTAT, &attrs); 442 if (res < 0) 443 return res; 444 445 attrs.atime = atime; 446 attrs.mtime = mtime; 447 448 do 449 { 450 const char *fixfname; 451 unsigned int fixfname_len = 0; 452 453 fixfname = sftpfs_fix_filename (path_element->path, &fixfname_len); 454 455 res = 456 libssh2_sftp_stat_ex (super_data->sftp_session, fixfname, fixfname_len, 457 LIBSSH2_SFTP_SETSTAT, &attrs); 458 if (res >= 0) 459 break; 460 461 if (sftpfs_is_sftp_error (super_data->sftp_session, res, LIBSSH2_FX_NO_SUCH_FILE)) 462 return -ENOENT; 463 464 if (sftpfs_is_sftp_error (super_data->sftp_session, res, LIBSSH2_FX_FAILURE)) 465 { 466 res = 0; /* need something like ftpfs_ignore_chattr_errors */ 467 break; 468 } 469 470 if (!sftpfs_waitsocket (super_data, res, mcerror)) 471 return -1; 472 } 473 while (res == LIBSSH2_ERROR_EAGAIN); 474 475 return res; 476 } 477 422 478 /* --------------------------------------------------------------------------------------------- */ 423 479 /** 424 480 * Changes the permissions of the file. -
src/vfs/sftpfs/internal.h
diff --git a/src/vfs/sftpfs/internal.h b/src/vfs/sftpfs/internal.h index 56da30ff1..2cce73772 100644
a b int sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror) 77 77 int sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror); 78 78 int sftpfs_readlink (const vfs_path_t * vpath, char *buf, size_t size, GError ** mcerror); 79 79 int sftpfs_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** mcerror); 80 int sftpfs_utime (const vfs_path_t * vpath, time_t atime, time_t mtime, GError ** mcerror); 80 81 int sftpfs_chmod (const vfs_path_t * vpath, mode_t mode, GError ** mcerror); 81 82 int sftpfs_unlink (const vfs_path_t * vpath, GError ** mcerror); 82 83 int sftpfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** mcerror); -
src/vfs/sftpfs/vfs_class.c
diff --git a/src/vfs/sftpfs/vfs_class.c b/src/vfs/sftpfs/vfs_class.c index 897f21c60..8caf2b32e 100644
a b sftpfs_cb_readlink (const vfs_path_t * vpath, char *buf, size_t size) 324 324 /** 325 325 * Callback for utime VFS-function. 326 326 * 327 * @param vpath unused328 * @param times unused329 * @return always 0327 * @param vpath path to file or directory 328 * @param times access and modification time to set 329 * @return 0 if success, negative value otherwise 330 330 */ 331 331 332 332 static int 333 333 sftpfs_cb_utime (const vfs_path_t * vpath, mc_timesbuf_t * times) 334 334 { 335 (void) vpath;336 (void) times;335 int rc; 336 GError *mcerror = NULL; 337 337 338 return 0; 338 #ifdef HAVE_UTIMENSAT 339 time_t atime = (*times)[0].tv_sec; 340 #else 341 time_t atime = times->actime; 342 #endif 343 344 #ifdef HAVE_UTIMENSAT 345 time_t mtime = (*times)[1].tv_sec; 346 #else 347 time_t mtime = times->modtime; 348 #endif 349 350 rc = sftpfs_utime (vpath, atime, mtime, &mcerror); 351 mc_error_message (&mcerror, NULL); 352 return rc; 339 353 } 340 354 341 355 /* --------------------------------------------------------------------------------------------- */