diff options
Diffstat (limited to 'mysys/my_redel.c')
-rw-r--r-- | mysys/my_redel.c | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/mysys/my_redel.c b/mysys/my_redel.c index 598a728393d..cf0986a7821 100644 --- a/mysys/my_redel.c +++ b/mysys/my_redel.c @@ -71,14 +71,28 @@ end: } /* my_redel */ - /* Copy stat from one file to another */ - /* Return -1 if can't get stat, 1 if wrong type of file */ +/** + Copy stat from one file to another + @fn my_copystat() + @param from Copy stat from this file + @param to Copy stat to this file + @param MyFlags Flags: + MY_WME Give error if something goes wrong + MY_FAE Abort operation if something goes wrong + If MY_FAE is not given, we don't return -1 for + errors from chown (which normally require root + privilege) + + @return 0 ok + -1 if can't get stat, + 1 if wrong type of file +*/ int my_copystat(const char *from, const char *to, int MyFlags) { struct stat statbuf; - if (stat((char*) from, &statbuf)) + if (stat(from, &statbuf)) { my_errno=errno; if (MyFlags & (MY_FAE+MY_WME)) @@ -87,7 +101,15 @@ int my_copystat(const char *from, const char *to, int MyFlags) } if ((statbuf.st_mode & S_IFMT) != S_IFREG) return 1; - VOID(chmod(to, statbuf.st_mode & 07777)); /* Copy modes */ + + /* Copy modes */ + if (chmod(to, statbuf.st_mode & 07777)) + { + my_errno= errno; + if (MyFlags & (MY_FAE+MY_WME)) + my_error(EE_CHANGE_PERMISSIONS, MYF(ME_BELL+ME_WAITTANG), from, errno); + return -1; + } #if !defined(__WIN__) && !defined(__NETWARE__) if (statbuf.st_nlink > 1 && MyFlags & MY_LINK_WARNING) @@ -95,9 +117,14 @@ int my_copystat(const char *from, const char *to, int MyFlags) if (MyFlags & MY_LINK_WARNING) my_error(EE_LINK_WARNING,MYF(ME_BELL+ME_WAITTANG),from,statbuf.st_nlink); } + /* Copy ownership */ if (chown(to, statbuf.st_uid, statbuf.st_gid)) { - my_error(EE_CANT_COPY_OWNERSHIP, MYF(ME_JUST_WARNING), to); + my_errno= errno; + if (MyFlags & MY_WME) + my_error(EE_CHANGE_OWNERSHIP, MYF(ME_BELL+ME_WAITTANG), from, errno); + if (MyFlags & MY_FAE) + return -1; } #endif /* !__WIN__ && !__NETWARE__ */ |