summaryrefslogtreecommitdiff
path: root/src/copy.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2009-08-26 00:32:43 +0100
committerPádraig Brady <P@draigBrady.com>2009-08-29 00:24:49 +0100
commit72f98388c36676e5c9ba6a72df5693c207862204 (patch)
treef0f54bfdb3a16d87cd180226021de9a7570bd9e7 /src/copy.c
parentf296cf4052c5299c7e6b1c14dcffa4785982a8ce (diff)
downloadcoreutils-72f98388c36676e5c9ba6a72df5693c207862204.tar.xz
cp --reflink: add an "auto" parameter to fall back to a normal copy
* doc/coreutils.texi (cp invocation): Document the new "auto" and "always" options to --reflink. * src/copy.c (copy_reg): Fall back to a standard copy when reflink() is not supported and --reflink=auto specified. * src/copy.h [struct cp_options] (reflink): Change type s/bool/enum/. * src/cp.c (usage): Describe the --reflink={always,auto} options and expand a little on what --reflink does. (main): parse the new parameters to --reflink and allow all --sparse options with --reflink=auto. * src/install.c (cp_option_init): Init the enum instead of bool. * src/mv.c (cp_option_init): Likewise. * tests/cp/reflink-auto: A new test for falling back to normal copy. * tests/Makefile.am: Reference the new test. * NEWS: Mention the new feature.
Diffstat (limited to 'src/copy.c')
-rw-r--r--src/copy.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/copy.c b/src/copy.c
index 5f84f7e43..17be63e56 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -635,14 +635,18 @@ copy_reg (char const *src_name, char const *dst_name,
goto close_src_and_dst_desc;
}
- if (x->reflink)
+ if (x->reflink_mode)
{
- if (clone_file (dest_desc, source_desc))
+ bool clone_ok = clone_file (dest_desc, source_desc) == 0;
+ if (clone_ok || x->reflink_mode == REFLINK_ALWAYS)
{
- error (0, errno, _("failed to clone %s"), quote (dst_name));
- return_val = false;
+ if (!clone_ok)
+ {
+ error (0, errno, _("failed to clone %s"), quote (dst_name));
+ return_val = false;
+ }
+ goto close_src_and_dst_desc;
}
- goto close_src_and_dst_desc;
}
{
@@ -2248,8 +2252,11 @@ valid_options (const struct cp_options *co)
assert (co != NULL);
assert (VALID_BACKUP_TYPE (co->backup_type));
assert (VALID_SPARSE_MODE (co->sparse_mode));
+ assert (VALID_REFLINK_MODE (co->reflink_mode));
assert (!(co->hard_link && co->symbolic_link));
- assert (!(co->reflink && co->sparse_mode != SPARSE_AUTO));
+ assert (!
+ (co->reflink_mode == REFLINK_ALWAYS
+ && co->sparse_mode != SPARSE_AUTO));
return true;
}