diff options
author | Jim Meyering <jim@meyering.net> | 2007-08-23 10:47:16 +0200 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2007-08-23 13:59:40 +0200 |
commit | 22ed81c410c197003782ba379cb3148306b0cd8a (patch) | |
tree | 3faddb492038c4eed405090a032c7312d072aa7e /src/copy.c | |
parent | 173524ed7d0bb5f458251b796f23a2dfc49a4b24 (diff) | |
download | coreutils-22ed81c410c197003782ba379cb3148306b0cd8a.tar.xz |
Move functions from copy.c into new modules, since ln needs them, too.
* bootstrap.conf (gnulib_modules): Add file-set.
* gl/lib/file-set.c (record_file, seen_file): Functions from copy.c.
* gl/lib/file-set.h: Add prototypes.
* gl/lib/hash-triple.c (triple_hash, triple_hash_no_name):
(triple_compare, triple_free): Functions from copy.c.
* gl/lib/hash-triple.h (struct F_triple): Define. From copy.c.
Add prototypes.
* gl/modules/file-set: New module.
* gl/modules/hash-triple: New module.
* src/Makefile.am (copy_sources): New variable.
(ginstall_SOURCES, cp_SOURCES, mv_SOURCES): Use it.
* src/copy.c: Include hash-triple.h.
No longer include hash-pjw.h.
(copy_internal): Don't pass a NULL third argument to record_file,
since that function no longer accepts that.
(record_file): Move this function to file-set.c.
Along the way, remove the code to allow a NULL stat-buffer pointer.
Adjust sole caller.
(seen_file): Move this function to file-set.c.
(struct F_triple): Move declaration to hash-triple.h.
(triple_compare, triple_free, triple_hash, triple_hash_no_name):
Move these functions to hash-triple.c.
Signed-off-by: Jim Meyering <jim@meyering.net>
Diffstat (limited to 'src/copy.c')
-rw-r--r-- | src/copy.c | 64 |
1 files changed, 6 insertions, 58 deletions
diff --git a/src/copy.c b/src/copy.c index b7bf92a6c..c1d8519d5 100644 --- a/src/copy.c +++ b/src/copy.c @@ -44,7 +44,7 @@ #include "full-write.h" #include "getpagesize.h" #include "hash.h" -#include "hash-pjw.h" +#include "hash-triple.h" #include "lchmod.h" #include "quote.h" #include "same.h" @@ -77,14 +77,6 @@ struct dir_list dev_t dev; }; -/* Describe a just-created or just-renamed destination file. */ -struct F_triple -{ - char *name; - ino_t st_ino; - dev_t st_dev; -}; - /* Initial size of the cp.dest_info hash table. */ #define DEST_INFO_INITIAL_CAPACITY 61 @@ -904,54 +896,6 @@ overwrite_prompt (char const *dst_name, struct stat const *dst_sb) } } -/* Hash an F_triple. */ -static size_t -triple_hash (void const *x, size_t table_size) -{ - struct F_triple const *p = x; - - /* Also take the name into account, so that when moving N hard links to the - same file (all listed on the command line) all into the same directory, - we don't experience any N^2 behavior. */ - /* FIXME-maybe: is it worth the overhead of doing this - just to avoid N^2 in such an unusual case? N would have - to be very large to make the N^2 factor noticable, and - one would probably encounter a limit on the length of - a command line before it became a problem. */ - size_t tmp = hash_pjw (p->name, table_size); - - /* Ignoring the device number here should be fine. */ - return (tmp | p->st_ino) % table_size; -} - -/* Hash an F_triple. */ -static size_t -triple_hash_no_name (void const *x, size_t table_size) -{ - struct F_triple const *p = x; - - /* Ignoring the device number here should be fine. */ - return p->st_ino % table_size; -} - -/* Compare two F_triple structs. */ -static bool -triple_compare (void const *x, void const *y) -{ - struct F_triple const *a = x; - struct F_triple const *b = y; - return (SAME_INODE (*a, *b) && same_name (a->name, b->name)) ? true : false; -} - -/* Free an F_triple. */ -static void -triple_free (void *x) -{ - struct F_triple *a = x; - free (a->name); - free (a); -} - /* Initialize the hash table implementing a set of F_triple entries corresponding to destination files. */ extern void @@ -1941,7 +1885,11 @@ copy_internal (char const *src_name, char const *dst_name, } if (command_line_arg) - record_file (x->dest_info, dst_name, NULL); + { + struct stat sb; + if (lstat (dst_name, &sb) == 0) + record_file (x->dest_info, dst_name, &sb); + } if ( ! preserve_metadata) return true; |