diff --git a/src/patch.c b/src/patch.c index 3794319..da4872a 100644 --- a/src/patch.c +++ b/src/patch.c @@ -580,7 +580,23 @@ main (int argc, char **argv) struct timespec new_time = pch_timestamp (! reverse); mode_t mode = file_type | ((set_mode ? new_mode : instat.st_mode) & S_IRWXUGO); - + /* If mode is changing and old mode is not + the same as expected in the patch, warn. */ + if ( (old_mode) && (old_mode != instat.st_mode) ) + { + if (! force) + { + say("Warning: original file's permission mode does not " + "match expected mode in patch file. Leaving " + "original mode in place. Use --force to overrule.\n"); + mode = instat.st_mode; + } + else + { + say("Warning: original file's permission mode does not " + "match expected mode in patch file.\n"); + } + } if ((set_time | set_utc) && new_time.tv_sec != -1) { struct timespec old_time = pch_timestamp (reverse); diff --git a/src/pch.c b/src/pch.c index cb54e03..5e81049 100644 --- a/src/pch.c +++ b/src/pch.c @@ -343,8 +343,14 @@ fetchmode (char const *str) } if (*s == '\r') s++; + /* + This check causes old mode to be reset every time. if (*s != '\n') + { + printf("DEBUG resetting mode due to newline\n"); mode = 0; + } + */ /* NOTE: The "diff --git" format always sets the file mode permission bits of symlinks to 0. (On Linux, symlinks actually always have