X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/f62c17e3786ac6643981d9ec68a1cd130ffcf149..ad301e487c1b50120d7ca1a9c7cc5fe80f50b944:/syscall.c diff --git a/syscall.c b/syscall.c index a56eb793..b198dbf4 100644 --- a/syscall.c +++ b/syscall.c @@ -1,5 +1,6 @@ /* Copyright (C) Andrew Tridgell 1998 + Copyright (C) 2002 by Martin Pool This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,9 +17,12 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* - syscall wrappers to ensure that nothing gets done in dry_run mode - */ +/** + * @file syscall.c + * + * Syscall wrappers to ensure that nothing gets done in dry_run mode + * and to handle system peculiarities. + **/ #include "rsync.h" @@ -106,13 +110,36 @@ int do_rename(char *fname1, char *fname2) return rename(fname1, fname2); } + +void trim_trailing_slashes(char *name) +{ + int l; + /* Some BSD systems cannot make a directory if the name + * contains a trailing slash. + * */ + + /* Don't change empty string; and also we can't improve on + * "/" */ + + l = strlen(name); + while (l > 1) { + if (name[--l] != '/') + break; + name[l] = '\0'; + } +} + + int do_mkdir(char *fname, mode_t mode) { - if (dry_run) return 0; - CHECK_RO + if (dry_run) + return 0; + CHECK_RO; + trim_trailing_slashes(fname); return mkdir(fname, mode); } + /* like mkstemp but forces permissions */ int do_mkstemp(char *template, mode_t perms) { @@ -132,7 +159,7 @@ int do_mkstemp(char *template, mode_t perms) } #else if (!mktemp(template)) return -1; - return open(template, O_RDWR|O_EXCL|O_CREAT, perms); + return do_open(template, O_RDWR|O_EXCL|O_CREAT, perms); #endif }