2012-10-16 11:48:01 +00:00
|
|
|
From 0cf7f38569e1c0ff65803342f63244f864d87141 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Michal Vyskocil <mvyskocil@suse.cz>
|
|
|
|
Date: Fri, 12 Oct 2012 15:24:16 +0200
|
|
|
|
Subject: [PATCH 10/10] add --permissions mode
|
|
|
|
|
|
|
|
With -p/--permissions mode enabled fdupes checks if the
|
|
|
|
uid/gid/secure-bits are same or not. In later case, files are not
|
|
|
|
considered as duplicates.
|
|
|
|
|
|
|
|
Requested-in: https://bugzilla.novell.com/show_bug.cgi?id=784670
|
|
|
|
---
|
|
|
|
fdupes.1 | 3 +++
|
|
|
|
fdupes.c | 25 ++++++++++++++++++++++++-
|
|
|
|
2 files changed, 27 insertions(+), 1 deletion(-)
|
|
|
|
|
2015-08-03 19:29:01 +00:00
|
|
|
Index: fdupes-fdupes-1.51/fdupes.1
|
|
|
|
===================================================================
|
|
|
|
--- fdupes-fdupes-1.51.orig/fdupes.1
|
|
|
|
+++ fdupes-fdupes-1.51/fdupes.1
|
2012-10-16 11:48:01 +00:00
|
|
|
@@ -63,6 +63,9 @@ below)
|
|
|
|
when used together with \-\-delete, preserve the first file in each
|
|
|
|
set of duplicates and delete the others without prompting the user
|
|
|
|
.TP
|
|
|
|
+.B -p --permissions
|
|
|
|
+don't consider files with different owner/group or permission bits as duplicates
|
|
|
|
+.TP
|
|
|
|
.B -v --version
|
|
|
|
display fdupes version
|
|
|
|
.TP
|
2015-08-03 19:29:01 +00:00
|
|
|
Index: fdupes-fdupes-1.51/fdupes.c
|
|
|
|
===================================================================
|
|
|
|
--- fdupes-fdupes-1.51.orig/fdupes.c
|
|
|
|
+++ fdupes-fdupes-1.51/fdupes.c
|
2012-10-16 11:48:01 +00:00
|
|
|
@@ -53,6 +53,7 @@
|
|
|
|
#define F_NOPROMPT 0x0400
|
|
|
|
#define F_SUMMARIZEMATCHES 0x0800
|
|
|
|
#define F_EXCLUDEHIDDEN 0x1000
|
|
|
|
+#define F_PERMISSIONS 0x2000
|
|
|
|
|
|
|
|
char *program_name;
|
|
|
|
|
2015-08-03 19:29:01 +00:00
|
|
|
@@ -481,6 +482,19 @@ int registerfile(filetree_t **branch, fi
|
2012-10-16 11:48:01 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
+int same_permissions(char* name1, char* name2)
|
|
|
|
+{
|
|
|
|
+ struct stat s1, s2;
|
|
|
|
+
|
|
|
|
+ if (stat(name1, &s1) != 0) return -1;
|
|
|
|
+ if (stat(name2, &s2) != 0) return -1;
|
|
|
|
+
|
|
|
|
+ return (s1.st_mode == s2.st_mode &&
|
|
|
|
+ s1.st_uid == s2.st_uid &&
|
|
|
|
+ s1.st_gid == s2.st_gid);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
file_t **checkmatch(filetree_t **root, filetree_t *checktree, file_t *file)
|
|
|
|
{
|
|
|
|
int cmpresult;
|
2015-08-03 19:29:01 +00:00
|
|
|
@@ -503,6 +517,10 @@ file_t **checkmatch(filetree_t **root, f
|
2012-10-16 11:48:01 +00:00
|
|
|
cmpresult = -1;
|
|
|
|
else
|
|
|
|
if (fsize > checktree->file->size) cmpresult = 1;
|
|
|
|
+ else
|
|
|
|
+ if (ISFLAG(flags, F_PERMISSIONS) &&
|
|
|
|
+ !same_permissions(file->d_name, checktree->file->d_name))
|
|
|
|
+ cmpresult = -1;
|
|
|
|
else {
|
|
|
|
if (checktree->file->crcpartial == NULL) {
|
|
|
|
crcsignature = getcrcpartialsignature(checktree->file->d_name);
|
2015-08-03 19:29:01 +00:00
|
|
|
@@ -979,6 +997,7 @@ void help_text()
|
2012-10-16 11:48:01 +00:00
|
|
|
printf(" -N --noprompt \ttogether with --delete, preserve the first file in\n");
|
|
|
|
printf(" \teach set of duplicates and delete the rest without\n");
|
2015-08-03 19:29:01 +00:00
|
|
|
printf(" \tprompting the user\n");
|
2012-10-16 11:48:01 +00:00
|
|
|
+ printf(" -p --permissions \tdon't consider files with different owner/group or permission bits as duplicates\n");
|
|
|
|
printf(" -v --version \tdisplay fdupes version\n");
|
|
|
|
printf(" -h --help \tdisplay this help message\n\n");
|
|
|
|
#ifdef OMIT_GETOPT_LONG
|
2015-08-03 19:29:01 +00:00
|
|
|
@@ -1022,6 +1041,7 @@ int main(int argc, char **argv) {
|
2012-10-16 11:48:01 +00:00
|
|
|
{ "noprompt", 0, 0, 'N' },
|
|
|
|
{ "summarize", 0, 0, 'm'},
|
|
|
|
{ "summary", 0, 0, 'm' },
|
|
|
|
+ { "permissions", 0, 0, 'p' },
|
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
#define GETOPT getopt_long
|
2015-08-03 19:29:01 +00:00
|
|
|
@@ -1033,7 +1053,7 @@ int main(int argc, char **argv) {
|
2012-10-16 11:48:01 +00:00
|
|
|
|
|
|
|
oldargv = cloneargs(argc, argv);
|
|
|
|
|
|
|
|
- while ((opt = GETOPT(argc, argv, "frRq1Ss::HlnAdvhNm"
|
|
|
|
+ while ((opt = GETOPT(argc, argv, "frRq1Ss::HlnAdvhNmp"
|
|
|
|
#ifndef OMIT_GETOPT_LONG
|
|
|
|
, long_options, NULL
|
|
|
|
#endif
|
2015-08-03 19:29:01 +00:00
|
|
|
@@ -1084,6 +1104,9 @@ int main(int argc, char **argv) {
|
2012-10-16 11:48:01 +00:00
|
|
|
case 'm':
|
|
|
|
SETFLAG(flags, F_SUMMARIZEMATCHES);
|
|
|
|
break;
|
|
|
|
+ case 'p':
|
|
|
|
+ SETFLAG(flags, F_PERMISSIONS);
|
|
|
|
+ break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Try `fdupes --help' for more information.\n");
|