-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag.pl
69 lines (63 loc) · 1.44 KB
/
tag.pl
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
#!/usr/bin/perl
use DBI;
use File::Basename;
use Time::HiRes;
use Digest::MD5 qw(md5_hex);
chdir('/');
$tmpfile = "/vagina/Scripts/NEW-TEMPFILE.txt";
$dbfile = "/vagina/tag.db";
$db = DBI->connect("dbi:SQLite:/vagina/tag.db", "", "",
{RaiseError => 1, AutoCommit => 1});
$argCount = @ARGV;
if(!defined(@ARGV))
{
print "Usage ./tag.pl PATH tags\nExample ./tag.pl /home home fileserver personal\n";
}else{
$searchPath = $ARGV[0];
if($argCount > 0)
{
shift(@ARGV);
$tags = join(",",@ARGV);
if($tags eq "")
{
$tags = "Random";
}
print "TAGS -> $tags\n";
}
&GetValues();
}
sub GetValues()
{
chomp(@files = `find $searchPath -type f`);
open TMPFILE, ">$tmpfile" or die $!;
$start = Time::HiRes::gettimeofday();
print TMPFILE "BEGIN;\n";
foreach(@files)
{
$filename = basename($_);
$path = dirname($_);
$md5 = md5_hex($_);
&CheckRows($md5);
}
print TMPFILE "END;\n";
}
sub CheckRows($md5)
{
$check = $db->prepare("select id from items where md5 = ?");
$check->bind_param(1, $md5);
$check->execute();
@sqlMD5 = $check->fetchrow_array;
$sqlTemp = @sqlMD5;
if($sqlTemp eq '0')
{
print TMPFILE "insert into items ( filename, path, tags, unixUser, md5 ) VALUES ( \"$filename\", \"$path\", \"$tags\", '$user', '$md5' );\n";
}
}
if(defined(@ARGV))
{
$end = Time::HiRes::gettimeofday();
printf("%.2f\n", $end - $start);
# $db->disconnect;
@insert = `sqlite3 $dbfile < $tmpfile`;
close(TMPFILE);
}