pkgsrc/sysutils/same/patches/patch-ab
minskim f1fc027f96 Import `same' from pkgsrc-wip. Packaged by Roland Illig.
The `same' utility looks for identical files and links them together
using either hard links or symbolic links, saving disk space.

Changes to the original version:
* the file ownership and permissions are checked.  (The original
  version checked only the file size)
* the messages in the "dry-run" mode were suggesting that anything on
  the disk would be modified.  They have been made clear.
2004-04-17 13:21:48 +00:00

133 lines
4.1 KiB
Text

$NetBSD: patch-ab,v 1.1.1.1 2004/04/17 13:21:48 minskim Exp $
--- same.c.orig 2000-10-16 10:04:15.000000000 +0200
+++ same.c 2004-01-31 20:14:29.000000000 +0100
@@ -143,6 +143,9 @@
dev_t device;
ino_t inode;
nlink_t nlink;
+ mode_t mode;
+ uid_t owner;
+ gid_t group;
long crc;
struct inode_entry *next;
struct name_entry *names;
@@ -254,11 +257,19 @@
fprintf(stderr, "%-60s: %10.2f s\n", "*** Total execution time ***",
(double)total_time/CLK_TCK);
fputs("Statistics:\n", stderr);
- fprintf(stderr, " Merged %lu hard links\n", stat_merge);
- fprintf(stderr, " Calculated %lu CRCs\n", stat_crc);
- fprintf(stderr, " Compared %lu files\n", stat_cmp);
- fprintf(stderr, " Linked %lu names for %lu identical files\n",
- stat_link_name, stat_link_inode);
+ if (o_dryrun) {
+ fprintf(stderr, " Would have merged %lu hard links\n", stat_merge);
+ fprintf(stderr, " Calculated %lu CRCs\n", stat_crc);
+ fprintf(stderr, " Compared %lu files\n", stat_cmp);
+ fprintf(stderr, " Would have linked %lu names for %lu identical files\n",
+ stat_link_name, stat_link_inode);
+ } else {
+ fprintf(stderr, " Merged %lu hard links\n", stat_merge);
+ fprintf(stderr, " Calculated %lu CRCs\n", stat_crc);
+ fprintf(stderr, " Compared %lu files\n", stat_cmp);
+ fprintf(stderr, " Linked %lu names for %lu identical files\n",
+ stat_link_name, stat_link_inode);
+ }
}
static void progress(int percent)
@@ -292,10 +303,10 @@
{
struct name_entry *names;
- printf("%sentry %p size %ld device %lx inode %lx nlink %d crc %08lx\n",
+ printf("%sentry %p size %ld device %lx inode %lx nlink %d mode %06o owner %d group %d crc %08lx\n",
indent, entry, (unsigned long)entry->size,
(unsigned long)entry->device, (unsigned long)entry->inode,
- entry->nlink, entry->crc);
+ entry->nlink, entry->mode, entry->owner, entry->group, entry->crc);
for (names = entry->names; names; names = names->next)
printf("%s %s\n", indent, names->name);
}
@@ -435,6 +446,9 @@
entry1 = entry0->next;
while (!stop && entry1) {
if ((entry0->size == entry1->size) &&
+ (entry0->mode == entry1->mode) &&
+ (entry0->owner == entry1->owner) &&
+ (entry0->group == entry1->group) &&
(entry0->size != 0 || o_nullfiles)) {
if (entry0->crc == -1)
calc_crc(entry0);
@@ -474,10 +488,16 @@
{
int res = 0;
- if (o_debug > 0)
- printf("unlink %s\n", name);
- if (!o_dryrun && ((res = unlink(name)) == -1))
+ if (o_debug > 0) {
+ if (o_dryrun) {
+ printf("would unlink %s\n", name);
+ } else {
+ printf("unlink %s\n", name);
+ }
+ }
+ if (!o_dryrun && ((res = unlink(name)) == -1)) {
fprintf(stderr, "unlink %s: %s\n", name, strerror(errno));
+ }
return res;
}
@@ -485,8 +505,13 @@
{
int res = 0;
- if (o_debug > 0)
- printf("link %s %s\n", master, slave);
+ if (o_debug > 0) {
+ if (o_dryrun) {
+ printf("would link %s %s\n", master, slave);
+ } else {
+ printf("link %s %s\n", master, slave);
+ }
+ }
if (!o_dryrun && ((res = link(master, slave)) == -1))
fprintf(stderr, "link %s %s: %s\n", master, slave, strerror(errno));
return res;
@@ -496,8 +521,13 @@
{
int res = 0;
- if (o_debug > 0)
- printf("symlink %s %s\n", master, slave);
+ if (o_debug > 0) {
+ if (o_dryrun) {
+ printf("would symlink %s %s\n", master, slave);
+ } else {
+ printf("symlink %s %s\n", master, slave);
+ }
+ }
if (!o_dryrun && ((res = symlink(master, slave)) == -1))
fprintf(stderr, "symlink %s %s: %s\n", master, slave, strerror(errno));
return res;
@@ -618,7 +648,7 @@
return NULL;
buf[strlen(buf)-1] = '\0';
if (lstat(buf, &sb) < 0) {
- fprintf(stderr, "stat %s: %s", buf, strerror(errno));
+ fprintf(stderr, "stat %s: %s\n", buf, strerror(errno));
exit (1);
}
} while (!S_ISREG(sb.st_mode));
@@ -630,6 +660,9 @@
entry->device = sb.st_dev;
entry->inode = sb.st_ino;
entry->nlink = sb.st_nlink;
+ entry->mode = sb.st_mode;
+ entry->owner = sb.st_uid;
+ entry->group = sb.st_gid;
entry->crc = -1;
return entry;