last_update: store in id3fs table, update when index is updated,
authorIan Beckwith <ianb@erislabs.net>
Fri, 24 Sep 2010 01:18:59 +0000 (02:18 +0100)
committerIan Beckwith <ianb@erislabs.net>
Fri, 24 Sep 2010 01:18:59 +0000 (02:18 +0100)
use as timestamp for everything

bin/id3fs
lib/ID3FS/DB.pm
lib/ID3FS/Fuse.pm

index 547b96d..62a631e 100755 (executable)
--- a/bin/id3fs
+++ b/bin/id3fs
@@ -34,6 +34,7 @@ if(@ARGV > 1 && !defined($basedir))
 }
 
 my $db=ID3FS::DB->new($me, $dbpath, $basedir, $ARGV[0]);
+$db->last_update(time());
 
 while(my $path=shift)
 {
index 11381c6..b6570ce 100644 (file)
@@ -84,7 +84,8 @@ sub create
            $self->{dbh}->do("CREATE INDEX $index ON " . $indexes{$index});
        }
     }
-    $self->cmd("INSERT INTO id3fs (schema_version) VALUES (?)", $SCHEMA_VERSION);
+    $self->cmd("INSERT INTO id3fs (schema_version, last_update) VALUES (?, ?)",
+              $SCHEMA_VERSION, time());
 }
 
 sub checkschema
@@ -99,6 +100,20 @@ sub checkschema
     }
 }
 
+sub last_update
+{
+    my($self, $newval)=@_;
+    if(defined($newval))
+    {
+       $self->cmd("UPDATE id3fs SET last_update=?", $newval);
+    }
+    else
+    {
+       ($newval)=$self->cmd_onerow("SELECT last_update from id3fs");
+    }
+    return $newval;
+}
+
 sub cmd_sth
 {
     my($self, $sql, @params)=@_;
@@ -548,7 +563,8 @@ sub last_insert_id
 __DATA__
 
 CREATE TABLE id3fs (
-    schema_version INTEGER
+    schema_version INTEGER,
+    last_update
 );
 
 CREATE TABLE files (
index cc38b65..732dd71 100644 (file)
@@ -65,12 +65,13 @@ sub getattr
     my($self, $filename)=@_;
     print "**GETATTR: $filename\n";
     my $path=ID3FS::Path->new($self->{db}, $filename);
+    my $last_update=$self->{db}->last_update();
     return(-ENOENT()) unless($path->isvalid());
     my($dev,$ino,$nlink)=(0,0,1);
     my $uid=$<;
     my $gid=(split(/ /, $( ))[0];
     my($rdev,$size)=(0,1);
-    my($atime,$mtime,$ctime)=(0,0,0);
+    my($atime,$mtime,$ctime)=($last_update) x 3;
     my($blksize,$blocks)=(512,1);
     my $mode=$self->mode( $path->isdir() ? $TYPE_DIR : $TYPE_SYMLINK );
     return($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,