[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-fileutils] --exclude option to cp
From: |
Marty Leisner |
Subject: |
[Bug-fileutils] --exclude option to cp |
Date: |
Tue, 19 Sep 2000 00:46:39 -0400 |
Moving around file systems, I wanted to add a --exclude
option to cp (in the style of du and tar).
I wanted this option for years!!
What I have works for cp (but it breaks other programs).
I didn't figure out how to make everything compile.
I'm not sure if --exclude is very useful in mv or install
(you can do rm before you mv), but it is very important for
cp...for example, moving around file systems, I wanted to exclude
lost+found...
Anyway, take a look at this...and if you want I'll write texinfo documentation
and see how to make install and mv compile...
A lot seemed to be guesswork, but it appears to have work with my
(limited) set of tests (doing what I wanted)
--- copy.c 2000/09/14 22:24:45 1.1
+++ copy.c 2000/09/14 23:52:56
@@ -36,6 +36,7 @@
#include "path-concat.h"
#include "quote.h"
#include "same.h"
+#include "exclude.h"
#define DO_CHOWN(Chown, File, New_uid, New_gid)
\
(Chown (File, New_uid, New_gid) \
@@ -67,6 +68,9 @@
int *copy_into_self,
int *rename_succeeded));
+
+static int test_to_avoid PARAMS ((const char *path));
+
/* The invocation name of this program. */
extern char *program_name;
@@ -189,6 +193,10 @@
int last_write_made_hole = 0;
int make_holes = (x->sparse_mode == SPARSE_ALWAYS);
+ if(1 == test_to_avoid(src_path)) {
+ return 0; /* fake success */
+ }
+
source_desc = open (src_path, O_RDONLY);
if (source_desc < 0)
{
@@ -572,6 +580,10 @@
int copied_as_regular = 0;
int ran_chown = 0;
+
+ if(1 == test_to_avoid(src_path)) {
+ return 0; /* fake success */
+ }
if (move_mode && rename_succeeded)
*rename_succeeded = 0;
@@ -1173,3 +1185,29 @@
return copy_internal (src_path, dst_path, nonexistent_dst, 0, NULL,
options, move_mode, copy_into_self, rename_succeeded);
}
+
+
+static int test_to_avoid(const char *path)
+{
+ extern struct exclude *exclude;
+ char *remainder;
+
+ remainder = rindex(path, '/');
+ if(!remainder) {
+ /* no slashes in file name */
+ remainder = path;
+ } else {
+ remainder++;
+ /* case of <name>/ ?? */
+ }
+
+ if(excluded_filename(exclude, remainder, 0)) {
+#if 0
+ printf("need to exclude %s\n", remainder);
+#endif
+ return 1;
+ }
+ return 0;
+
+}
+
--- cp.c 2000/09/10 22:17:14 1.1
+++ cp.c 2000/09/14 22:27:04
@@ -36,6 +36,7 @@
#include "dirname.h"
#include "path-concat.h"
#include "quote.h"
+#include "exclude.h"
#define ASSIGN_BASENAME_STRDUPA(Dest, File_name) \
do \
@@ -74,7 +75,8 @@
SPARSE_OPTION,
STRIP_TRAILING_SLASHES_OPTION,
PARENTS_OPTION,
- UNLINK_DEST_BEFORE_OPENING
+ UNLINK_DEST_BEFORE_OPENING,
+ EXCLUDE_OPTION
};
void strip_trailing_slashes ();
@@ -92,6 +94,9 @@
as its destination instead of the usual "e_dir/e_file." */
static int flag_path = 0;
+/* File name patterns to exclude. */
+struct exclude *exclude;
+
/* Remove any trailing slashes from each SOURCE argument. */
static int remove_trailing_slashes;
@@ -114,6 +119,8 @@
{"backup", optional_argument, NULL, 'b'},
{"dereference", no_argument, NULL, 'L'},
{"force", no_argument, NULL, 'f'},
+ {"exclude", required_argument, 0, EXCLUDE_OPTION },
+ {"exclude-from", required_argument, 0, 'X' },
{"sparse", required_argument, NULL, SPARSE_OPTION},
{"interactive", no_argument, NULL, 'i'},
{"link", no_argument, NULL, 'l'},
@@ -187,6 +194,8 @@
destination file is missing\n\
-v, --verbose explain what is being done\n\
-x, --one-file-system stay on this file system\n\
+ -X FILE, --exclude-from=FILE Exclude files that match any pattern in FILE.\n\
+ --exclude=PAT Exclude files that match PAT.\n\
--help display this help and exit\n\
--version output version information and exit\n\
\n\
@@ -699,13 +708,15 @@
atexit (close_stdout);
+ exclude = new_exclude();
+
cp_option_init (&x);
/* FIXME: consider not calling getenv for SIMPLE_BACKUP_SUFFIX unless
we'll actually use backup_suffix_string. */
backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
- while ((c = getopt_long (argc, argv, "abdfHilLprsuvxPRS:V:", long_opts,
NULL))
+ while ((c = getopt_long (argc, argv, "abdfHilLprsuvxPRS:V:X:", long_opts,
NULL))
!= -1)
{
switch (c)
@@ -825,6 +836,15 @@
make_backups = 1;
backup_suffix_string = optarg;
break;
+
+ case 'X':
+ if (add_exclude_file (add_exclude, exclude, optarg, '\n') != 0)
+ error (1, errno, "%s", quote (optarg));
+ break;
+
+ case EXCLUDE_OPTION:
+ add_exclude (exclude, optarg);
+ break;
case_GETOPT_HELP_CHAR;
Marty Leisner
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-fileutils] --exclude option to cp,
Marty Leisner <=