forked from pool/fdupes
111 lines
3.4 KiB
Diff
111 lines
3.4 KiB
Diff
|
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(-)
|
||
|
|
||
|
diff --git a/fdupes.1 b/fdupes.1
|
||
|
index 9263adc..e0516f1 100644
|
||
|
--- a/fdupes.1
|
||
|
+++ b/fdupes.1
|
||
|
@@ -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
|
||
|
diff --git a/fdupes.c b/fdupes.c
|
||
|
index 678f31f..b3275a9 100644
|
||
|
--- a/fdupes.c
|
||
|
+++ b/fdupes.c
|
||
|
@@ -53,6 +53,7 @@
|
||
|
#define F_NOPROMPT 0x0400
|
||
|
#define F_SUMMARIZEMATCHES 0x0800
|
||
|
#define F_EXCLUDEHIDDEN 0x1000
|
||
|
+#define F_PERMISSIONS 0x2000
|
||
|
|
||
|
char *program_name;
|
||
|
|
||
|
@@ -481,6 +482,19 @@ int registerfile(filetree_t **branch, file_t *file)
|
||
|
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;
|
||
|
@@ -503,6 +517,10 @@ file_t **checkmatch(filetree_t **root, filetree_t *checktree, file_t *file)
|
||
|
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);
|
||
|
@@ -976,6 +994,7 @@ void help_text()
|
||
|
printf(" -N --noprompt \ttogether with --delete, preserve the first file in\n");
|
||
|
printf(" \teach set of duplicates and delete the rest without\n");
|
||
|
printf(" \twithout prompting the user\n");
|
||
|
+ 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
|
||
|
@@ -1019,6 +1038,7 @@ int main(int argc, char **argv) {
|
||
|
{ "noprompt", 0, 0, 'N' },
|
||
|
{ "summarize", 0, 0, 'm'},
|
||
|
{ "summary", 0, 0, 'm' },
|
||
|
+ { "permissions", 0, 0, 'p' },
|
||
|
{ 0, 0, 0, 0 }
|
||
|
};
|
||
|
#define GETOPT getopt_long
|
||
|
@@ -1030,7 +1050,7 @@ int main(int argc, char **argv) {
|
||
|
|
||
|
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
|
||
|
@@ -1081,6 +1101,9 @@ int main(int argc, char **argv) {
|
||
|
case 'm':
|
||
|
SETFLAG(flags, F_SUMMARIZEMATCHES);
|
||
|
break;
|
||
|
+ case 'p':
|
||
|
+ SETFLAG(flags, F_PERMISSIONS);
|
||
|
+ break;
|
||
|
|
||
|
default:
|
||
|
fprintf(stderr, "Try `fdupes --help' for more information.\n");
|
||
|
--
|
||
|
1.7.11.5
|
||
|
|