Subversion Repositories checksum-tools

Rev

Rev 15 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15 Rev 16
Line 19... Line 19...
19
 
19
 
20
// This script generates MD5 files
20
// This script generates MD5 files
21
// If there is already an MD5 file existing, only new files get appended to the existing MD5 files.
21
// If there is already an MD5 file existing, only new files get appended to the existing MD5 files.
22
 
22
 
23
function _rec($directory) {
23
function _rec($directory) {
-
 
24
        $res = true;
-
 
25
 
24
        if (!is_dir($directory)) {
26
        if (!is_dir($directory)) {
25
                fwrite(STDERR, "Invalid directory path '$directory'\n");
27
                fwrite(STDERR, "Invalid directory path '$directory'\n");
26
                return false;
28
                return false;
27
        }
29
        }
28
 
30
 
Line 66... Line 68...
66
 
68
 
67
                        if (!file_exists($md5_file)) {
69
                        if (!file_exists($md5_file)) {
68
                                file_put_contents($md5_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM
70
                                file_put_contents($md5_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM
69
                        }
71
                        }
70
 
72
 
71
                        if (!in_array($file, $existing_files)) {
73
                        if (!in_arrayi($file, $existing_files)) {
72
                                $md5 = strtolower(md5_file($fullpath));
74
                                $hash = md5_file($fullpath);
-
 
75
                                if ($hash === false) {
-
 
76
                                        fwrite(STDERR, "Cannot get hash of '$fullpath'\n");
-
 
77
                                        $res = false;
-
 
78
                                } else {
-
 
79
                                        $md5 = strtolower($hash);
73
                                file_put_contents($md5_file, "$md5 *$file\r\n", FILE_APPEND);
80
                                        file_put_contents($md5_file, "$md5 *$file\r\n", FILE_APPEND);
74
                        }
81
                                }
-
 
82
                        }
75
                } else {
83
                } else {
76
                        // For some reason, some files on a NTFS volume are "FIFO" pipe files?!
84
                        // For some reason, some files on a NTFS volume are "FIFO" pipe files?!
77
                        fwrite(STDERR, "Warning: $fullpath is not a regular file!\n");
85
                        fwrite(STDERR, "Warning: $fullpath is not a regular file!\n");
-
 
86
                        $res = false;
78
                }
87
                }
79
        }
88
        }
80
 
89
 
81
        return true;
90
        return $res;
82
}
91
}
83
 
92
 
84
function md5_get_files($filename) {
93
function md5_get_files($filename) {
85
        $out = array();
94
        $out = array();
86
        $lines = file($filename);
95
        $lines = file($filename);
Line 97... Line 106...
97
        }
106
        }
98
 
107
 
99
        return $out;
108
        return $out;
100
}
109
}
101
 
110
 
-
 
111
function in_arrayi($needle, $haystack) {
-
 
112
        // Source: https://www.php.net/manual/en/function.in-array.php#89256
-
 
113
        return in_array(strtolower($needle), array_map('strtolower', $haystack));
-
 
114
}
-
 
115
 
102
# ---
116
# ---
103
 
117
 
104
$show_verbose = false;
118
$show_verbose = false;
105
$do_recursive = false;
119
$do_recursive = false;
106
$dirs = array();
120
$dirs = array();