-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsizes.awk
More file actions
40 lines (40 loc) · 1.48 KB
/
Copy pathsizes.awk
File metadata and controls
40 lines (40 loc) · 1.48 KB
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
BEGIN {
printf "CREATE TABLE IF NOT EXISTS directories(path text NOT NULL PRIMARY KEY, files INT NOT NULL, kballocated INT NOT NULL);\n";
printf ".output /dev/null\n";
printf "PRAGMA busy_timeout=20000;\n";
printf "PRAGMA journal_mode = WAL;\n";
printf "PRAGMA synchronous = OFF;\n";
printf ".output stdout\n";
}
function dirname (pathname){
if (!sub(/\/[^\/]*\/?$/, "", pathname))
return "."
else if (pathname != "")
return pathname
else
return "/"
}
{
split($1, fields, " ") ;
kballocated=fields[6];
directory = dirname($2)
# Sanitize output for sqlite, just drop single quotes..
gsub("'", "", directory)
a[directory] += kballocated ;
b[directory] += 1 ;
# flush after every million lines to avoid using too much memory
if (NR%1000000)
{
printf "BEGIN IMMEDIATE TRANSACTION;\n";
for (i in a) printf "INSERT INTO directories(path, files, kballocated) VALUES('%s', %i, %i) ON CONFLICT(path) DO UPDATE SET files=files+%i, kballocated=kballocated+%i;\n", i, b[i], a[i], b[i], a[i]
printf "END TRANSACTION;\n";
delete a;
delete b;
delete c;
}
}
END {
printf "BEGIN IMMEDIATE TRANSACTION;\n";
for (i in a) printf "INSERT INTO directories(path, files, kballocated) VALUES('%s', %i, %i) ON CONFLICT(path) DO UPDATE SET files=files+%i, kballocated=kballocated+%i;\n", i, b[i], a[i], b[i], a[i]
printf "END TRANSACTION;\n";
}