From dbe1f77775037f1fbcfc89a84a58fa48dcba5b28 Mon Sep 17 00:00:00 2001 From: Ondrej Oprala Date: Mon, 6 Aug 2012 13:18:22 +0200 Subject: [PATCH] cp: Fix the --no-preserve=mode option * NEWS: Mention the fix. * src/copy.c (preserve_metadata): Add a condition to properly handle the --no-preserve=mode option. * src/copy.h (struct cp_options): Add a new boolean. * src/cp.c (cp_option_init,decode_preserve_arg): Set the new boolean value according to specified options. --- NEWS | 3 +++ src/copy.c | 5 +++++ src/copy.h | 1 + src/cp.c | 2 ++ 4 files changed, 11 insertions(+) diff --git a/NEWS b/NEWS index ca4568a..ba320e8 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,9 @@ GNU coreutils NEWS -*- outline -*- ** Bug fixes + cp --no-preserve=mode now no longer preserves the original file's + permissions but correctly sets mode specified by 0666 & ~umask + cksum now prints checksums atomically so that concurrent processes will not intersperse their output. [the bug dates back to the initial implementation] diff --git a/src/copy.c b/src/copy.c index 2558fea..9b2746f 100644 --- a/src/copy.c +++ b/src/copy.c @@ -1151,6 +1151,11 @@ preserve_metadata: if (set_acl (dst_name, dest_desc, x->mode) != 0) return_val = false; } + else if (x->explicit_no_preserve) + { + set_acl(dst_name, dest_desc, 0666 & ~cached_umask ()); + return_val = false; + } else if (omitted_permissions) { omitted_permissions &= ~ cached_umask (); diff --git a/src/copy.h b/src/copy.h index d70c09e..e93366c 100644 --- a/src/copy.h +++ b/src/copy.h @@ -157,6 +157,7 @@ struct cp_options bool preserve_ownership; bool preserve_mode; bool preserve_timestamps; + bool explicit_no_preserve; /* Enabled for mv, and for cp by the --preserve=links option. If true, attempt to preserve in the destination files any diff --git a/src/cp.c b/src/cp.c index 6649af2..bf70f9e 100644 --- a/src/cp.c +++ b/src/cp.c @@ -783,6 +783,7 @@ cp_option_init (struct cp_options *x) x->preserve_links = false; x->preserve_mode = false; x->preserve_timestamps = false; + x->explicit_no_preserve = false; x->preserve_security_context = false; x->require_preserve_context = false; x->preserve_xattr = false; @@ -860,6 +861,7 @@ decode_preserve_arg (char const *arg, struct cp_options *x, bool on_off) { case PRESERVE_MODE: x->preserve_mode = on_off; + x->explicit_no_preserve = ~on_off; break; case PRESERVE_TIMESTAMPS: -- 1.7.11.2