Skip to content

Commit

Permalink
Do not abort if chown/chmod fails but the file is already correct
Browse files Browse the repository at this point in the history
- This small patch makes rpm not abort the installation if
  chown()/chmod() failed but the files already have the correct
  ownership/mode. It also allows a failed mtime update on directories.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
  • Loading branch information
mlschroe authored and pmatilai committed May 17, 2011
1 parent 39800e9 commit 09d554d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,11 @@ static int fsmRename(FSM_t fsm)
static int fsmChown(FSM_t fsm)
{
int rc = chown(fsm->path, fsm->sb.st_uid, fsm->sb.st_gid);
if (rc < 0) {
struct stat st;
if (lstat(fsm->path, &st) == 0 && st.st_uid == fsm->sb.st_uid && st.st_gid == fsm->sb.st_gid)
rc = 0;
}
if (_fsm_debug && (FSM_CHOWN & FSM_SYSCALL))
rpmlog(RPMLOG_DEBUG, " %8s (%s, %d, %d) %s\n", fileStageString(FSM_CHOWN),
fsm->path, (int)fsm->sb.st_uid, (int)fsm->sb.st_gid,
Expand All @@ -1458,6 +1463,11 @@ static int fsmLChown(FSM_t fsm)
{
int rc = 0;
rc = lchown(fsm->path, fsm->sb.st_uid, fsm->sb.st_gid);
if (rc < 0) {
struct stat st;
if (lstat(fsm->path, &st) == 0 && st.st_uid == fsm->sb.st_uid && st.st_gid == fsm->sb.st_gid)
rc = 0;
}
if (_fsm_debug && (FSM_LCHOWN & FSM_SYSCALL))
rpmlog(RPMLOG_DEBUG, " %8s (%s, %d, %d) %s\n", fileStageString(FSM_LCHOWN),
fsm->path, (int)fsm->sb.st_uid, (int)fsm->sb.st_gid,
Expand All @@ -1469,6 +1479,11 @@ static int fsmLChown(FSM_t fsm)
static int fsmChmod(FSM_t fsm)
{
int rc = chmod(fsm->path, (fsm->sb.st_mode & 07777));
if (rc < 0) {
struct stat st;
if (lstat(fsm->path, &st) == 0 && (st.st_mode & 07777) == (fsm->sb.st_mode & 07777))
rc = 0;
}
if (_fsm_debug && (FSM_CHMOD & FSM_SYSCALL))
rpmlog(RPMLOG_DEBUG, " %8s (%s, 0%04o) %s\n", fileStageString(FSM_CHMOD),
fsm->path, (unsigned)(fsm->sb.st_mode & 07777),
Expand Down Expand Up @@ -2029,6 +2044,9 @@ if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
st->st_mtime = rpmfiFMtimeIndex(fi, fsm->ix);
rc = fsmUtime(fsm);
st->st_mtime = mtime;
/* utime error is not critical for directories */
if (rc && S_ISDIR(st->st_mode))
rc = 0;
}
#if WITH_CAP
if (!rc && !S_ISDIR(st->st_mode) && !getuid()) {
Expand Down

0 comments on commit 09d554d

Please sign in to comment.