5d08d14
From 76126e2831580d0df20530f4d6f72189bd4f0b9a Mon Sep 17 00:00:00 2001
5d08d14
From: Paul Eggert <eggert@cs.ucla.edu>
5d08d14
Date: Thu, 18 Jun 2020 22:16:24 -0700
5d08d14
Subject: [PATCH] cp: default to COW
5d08d14
MIME-Version: 1.0
5d08d14
Content-Type: text/plain; charset=UTF-8
5d08d14
Content-Transfer-Encoding: 8bit
5d08d14
5d08d14
Likewise for ‘install’.  Proposed in Bug#24400, and long past due.
5d08d14
* NEWS:
5d08d14
* doc/coreutils.texi (cp invocation):
5d08d14
* src/copy.h (enum Reflink_type): Document this.
5d08d14
* src/cp.c (cp_option_init):
5d08d14
* src/install.c (cp_option_init): Implement this.
5d08d14
5d08d14
Upstream-commit: 25725f9d41735d176d73a757430739fb71c7d043
5d08d14
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
5d08d14
---
5d08d14
 doc/coreutils.texi | 19 ++++++++++++-------
5d08d14
 src/copy.h         |  4 ++--
5d08d14
 src/cp.c           |  2 +-
5d08d14
 src/install.c      |  2 +-
5d08d14
 4 files changed, 16 insertions(+), 11 deletions(-)
5d08d14
5d08d14
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
5d08d14
index 02e0c1c..2382a16 100644
5d08d14
--- a/doc/coreutils.texi
5d08d14
+++ b/doc/coreutils.texi
5d08d14
@@ -8854,12 +8854,14 @@ The @var{when} value can be one of the following:
5d08d14
 
5d08d14
 @table @samp
5d08d14
 @item always
5d08d14
-The default behavior: if the copy-on-write operation is not supported
5d08d14
+If the copy-on-write operation is not supported
5d08d14
 then report the failure for each file and exit with a failure status.
5d08d14
+Plain @option{--reflink} is equivalent to @option{--reflink=when}.
5d08d14
 
5d08d14
 @item auto
5d08d14
 If the copy-on-write operation is not supported then fall back
5d08d14
 to the standard copy behavior.
5d08d14
+This is the default if no @option{--reflink} option is given.
5d08d14
 
5d08d14
 @item never
5d08d14
 Disable copy-on-write operation and use the standard copy behavior.
5d08d14
@@ -8868,12 +8870,6 @@ Disable copy-on-write operation and use the standard copy behavior.
5d08d14
 This option is overridden by the @option{--link}, @option{--symbolic-link}
5d08d14
 and @option{--attributes-only} options, thus allowing it to be used
5d08d14
 to configure the default data copying behavior for @command{cp}.
5d08d14
-For example, with the following alias, @command{cp} will use the
5d08d14
-minimum amount of space supported by the file system.
5d08d14
-
5d08d14
-@example
5d08d14
-alias cp='cp --reflink=auto --sparse=always'
5d08d14
-@end example
5d08d14
 
5d08d14
 @item --remove-destination
5d08d14
 @opindex --remove-destination
5d08d14
@@ -8918,6 +8914,15 @@ This is useful in creating a file for use with the @command{mkswap} command,
5d08d14
 since such a file must not have any holes.
5d08d14
 @end table
5d08d14
 
5d08d14
+For example, with the following alias, @command{cp} will use the
5d08d14
+minimum amount of space supported by the file system.
5d08d14
+(Older versions of @command{cp} can also benefit from
5d08d14
+@option{--reflink=auto} here.)
5d08d14
+
5d08d14
+@example
5d08d14
+alias cp='cp --sparse=always'
5d08d14
+@end example
5d08d14
+
5d08d14
 @optStripTrailingSlashes
5d08d14
 
5d08d14
 @item -s
5d08d14
diff --git a/src/copy.h b/src/copy.h
5d08d14
index 874d6f7..a0ad494 100644
5d08d14
--- a/src/copy.h
5d08d14
+++ b/src/copy.h
5d08d14
@@ -46,10 +46,10 @@ enum Sparse_type
5d08d14
 /* Control creation of COW files.  */
5d08d14
 enum Reflink_type
5d08d14
 {
5d08d14
-  /* Default to a standard copy.  */
5d08d14
+  /* Do a standard copy.  */
5d08d14
   REFLINK_NEVER,
5d08d14
 
5d08d14
-  /* Try a COW copy and fall back to a standard copy.  */
5d08d14
+  /* Try a COW copy and fall back to a standard copy; this is the default.  */
5d08d14
   REFLINK_AUTO,
5d08d14
 
5d08d14
   /* Require a COW copy and fail if not available.  */
5d08d14
diff --git a/src/cp.c b/src/cp.c
5d08d14
index 0193df8..9e7ad14 100644
5d08d14
--- a/src/cp.c
5d08d14
+++ b/src/cp.c
5d08d14
@@ -796,7 +796,7 @@ cp_option_init (struct cp_options *x)
5d08d14
   x->move_mode = false;
5d08d14
   x->install_mode = false;
5d08d14
   x->one_file_system = false;
5d08d14
-  x->reflink_mode = REFLINK_NEVER;
5d08d14
+  x->reflink_mode = REFLINK_AUTO;
5d08d14
 
5d08d14
   x->preserve_ownership = false;
5d08d14
   x->preserve_links = false;
5d08d14
diff --git a/src/install.c b/src/install.c
5d08d14
index 4ab44a6..aef16ca 100644
5d08d14
--- a/src/install.c
5d08d14
+++ b/src/install.c
5d08d14
@@ -264,7 +264,7 @@ cp_option_init (struct cp_options *x)
5d08d14
 {
5d08d14
   cp_options_default (x);
5d08d14
   x->copy_as_regular = true;
5d08d14
-  x->reflink_mode = REFLINK_NEVER;
5d08d14
+  x->reflink_mode = REFLINK_AUTO;
5d08d14
   x->dereference = DEREF_ALWAYS;
5d08d14
   x->unlink_dest_before_opening = true;
5d08d14
   x->unlink_dest_after_failed_open = false;
5d08d14
-- 
5d08d14
2.25.4
5d08d14