summaryrefslogtreecommitdiff
blob: 1815f7b6d1525b0ef3456661a1b9bcfa12f3b61d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Source: Peter Volkov <pva@gentoo.org>
Upstream: notified (sent email to <adrian2 AT caribe DOT net>
Reason: bugs.gentoo.org/237828 comment #1
With USE=md5sum-external fails on filenames with spaces in their names.

Updated on 2009/06/20:
 * Fixed free due to wrong length of memory allocation bugs.gentoo.org/273597
 * Now works with filename that have " in name...

--- fdupes.c	2009-06-20 10:51:31 +0000
+++ fdupes.c	2009-06-20 13:38:39 +0000
@@ -291,17 +291,48 @@
 char *getcrcsignature(char *filename)
 {
   static char signature[256];
+  char *backslashedfilename;
   char *command;
   char *separator;
   FILE *result;
-
-  command = (char*) malloc(strlen(filename)+strlen(EXTERNAL_MD5)+2);
+  int i=0;
+  int j=0;
+  int numofquotes=0;
+
+  /* Find number of " in filename */
+  while ( filename[i] != '\0' ) {
+    if ( filename[i] == '\"' )
+      numofquotes++;
+      i++;
+  }
+
+  backslashedfilename = (char*) malloc(strlen(filename)+numofquotes+1);
+  if (backslashedfilename == NULL) {
+    errormsg("out of memory\n");
+    exit(1);
+  }
+
+  /* Put backslash before each " */
+  i=0;
+  while ( filename[i] != '\0' ) {
+    if ( filename[i] == '\"' ) {
+      backslashedfilename[j]='\\';
+      j++;
+    }
+    backslashedfilename[j]=filename[i];
+    i++;
+    j++;
+  }
+  backslashedfilename[j]='\0';
+
+  command = (char*) malloc(strlen(backslashedfilename)+strlen(EXTERNAL_MD5)+6);
   if (command == NULL) {
     errormsg("out of memory\n");
     exit(1);
   }
 
-  sprintf(command, "%s %s", EXTERNAL_MD5, filename);
+  /* Qoutation required to works spaces in filenames */
+  sprintf(command, "%s \"%s\"", EXTERNAL_MD5, backslashedfilename);
 
   result = popen(command, "r");
   if (result == NULL) {
@@ -309,6 +340,7 @@
     exit(1);
   }
  
+  free(backslashedfilename);
   free(command);
 
   if (fgets(signature, 256, result) == NULL) {