* updated ktuberling (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / package / archiver / mine / check-file-unlink.patch
blob9d97fbfc726426868fafcd5b4a90d6b3b9a630bb
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../mine/check-file-unlink.patch
5 # Copyright (C) 2006-2016 The T2 SDE Project
6 #
7 # More information can be found in the files COPYING and README.
8 #
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 # --- T2-COPYRIGHT-NOTE-END ---
17 This fixes detecting unliked (removed, deleted) files as modified.
19 - Rene Rebe <rene@exactcode.de>
21 --- mine-0.23/md5sum.c.orig 2016-03-23 23:08:37.515390469 +0100
22 +++ mine-0.23/md5sum.c 2016-03-23 23:20:45.379405046 +0100
23 @@ -1,6 +1,7 @@
25 * GEM MINE - The ROCK Linux Package Manager
26 * Copyright (C) 2002-2005 Clifford Wolf
27 + * Copyright (C) 2006-2016 Rene Rebe
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 @@ -34,11 +35,11 @@
33 char * md5sum_create(char * root, char * filename) {
34 char realfilename[1024];
35 - struct stat statbuf;
36 + struct stat st;
38 snprintf(realfilename, 1024, "%s/%s", root, filename);
39 - return (stat(realfilename, &statbuf) != 0 || S_ISFIFO(statbuf.st_mode))
40 - ? "" : md5_file(realfilename);
41 + return (!lstat(realfilename, &st) && S_ISREG(st.st_mode) ?
42 + md5_file(realfilename) : "");
45 /* Returns 1 if file is duplicate, 2 if file is modified. */
46 @@ -48,9 +49,14 @@
48 md5_f = md5sum_create(root, filename);
49 md5_d = memdb_get(&md5_memdb, filename);
51 - if (md5_f == NULL || strcmp(md5_f, "") == 0)
52 - return 0;
54 + /* this is a bit tricky, directory also have no hash! */
55 + if (md5_f == NULL || strcmp(md5_f, "") == 0) {
56 + if (md5_d == NULL || strcmp(md5_d, "") == 0)
57 + return 0; /* directory or symlink, no hash in db */
58 + else
59 + return 2; /* modified, was removed */
60 + }
61 else if (md5_d == NULL)
62 return 1;
63 else if (strcmp(md5_f, md5_d) == 0)