[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [coldsync-hackers] syncing of creation/modification dates



David A. Desrosiers wrote:

 >> Plucker creates a cache file on the Palm during usage, and updating
 >> a Plucker document should invalidates this cache. The problem is
 >> that Plucker invalidates that cache when the creation date on a
 >> document changes, but neither the creation or the modification date
 >> are updated by the generic conduit!
 >
 > It's not a cache file, it's where the metadata of that document is
 > stored, such as what page you left off at when you last opened it,
 > and other values.

Ok, agreed that its not a cache file, because it also contains other 
"non-critical" data, like you mentioned (also of interest is the list of 
visited links). That's why I'd rather not pre-emptively delete the 
metadata file, unless I changed anything.

 > The reason that you need to sync the creation time of the new Plucker
 > pdb you install and the Plkr-MyNewPdb.pdb file is because they could
 > be different files. Either update the creation time on the
 > MyNewPdb.pdb file, which would cause Plucker to delete (and recreate)
 > the Plkr-MyNewPdb.pdb file, or delete the Plkr-MyNewPdb.pdb file when
 > you install your new MyNewPdb.pdb file.
 >
 > ..unless I misunderstand you here. Are actually creating the raw
 > records of the pdb with coldsync, and building the pdb on disk,
 > before syncing to the Palm (replacing the distiller's pdb create
 > actions) or are you just syncing the pdb on disk to the Palm?

I don't use the "plucker-build -f" mode, I have "plucker-build -q -c" in 
a cron job, every hour, and I *update* (never create, this being a 
"fetch" conduit) a previously installed PDB. I created the PDB using 
"plucker-build -f", though.

IMHO, the "-f" mode of Plucker is next to useless for something like 
updating from a ColdSync conduit, since you have to delete the PDB on 
the Palm before installing a new one. I also try to make things as fast 
as possible (if some records are completely identical, I don't touch 
them, so only the deleted/modified/new records get synced).

It works perfect, except for ColdSync not updating the creation time 
(which I'm careful not to change if I didn't actually change the PDB, 
and would thus clear out the metadata correctly).

Of course, I could change the whole thing into a sync conduit rather 
than a fetch conduit, but having ColdSync's generic conduit do the grunt 
work for me is quite attractive... :-)

Attached is the current state of the conduit, if anyone is interested or 
could review the code... Thanks!

-- 
Pierre Phaneuf
http://advogato.org/person/pphaneuf/
#! /usr/bin/perl -w

use strict;

use ColdSync;
use Palm::Raw ();

%HEADERS = (
	    'File' => "Home Page",
	    'Cache' => "$ENV{HOME}/.plucker/cache",
	    'Verbose' => 0
	   );

sub update_home {
  my %params = @_;
  my $pdb = $params{PDB};
  my $pdbname = $params{File} || 'Home Page';
  my $cachedir = $params{Cache} || '/home/pp/.plucker/cache';
  my $debug = $params{Verbose} || 0;
  my $prefix = $params{Prefix} || '';
  my $modified = 0;
  my @files;

  if(!defined($pdb)) {
    die "PDB not defined";
  }

  if($pdb->{name} ne $pdbname
     || $pdb->{creator} ne 'Plkr'
     || $pdb->{type} ne 'Data') {
    return;
  }

  print "${prefix}PDB: $pdb->{name} ($pdb->{mtime})\n" if $debug;

  opendir(DIR, $cachedir);
  rewinddir(DIR);
  @files = readdir(DIR);
  closedir(DIR);

  @files = sort({$a <=> $b} grep(!/^\./, @files));

  foreach my $record (@{$pdb->{records}}) {
    if(!grep($record->{id} == $_, @files)) {
      if(!defined($record->{attributes}{deleted})) {
	print "${prefix}deleting unneeded record $record->{id}\n" if $debug;
	$pdb->delete_Record($record, 1);
	++$modified;
      }
    }
  }

  foreach my $file (@files) {
    my $record;
    my $data;

    if(!open(FILE, "< $cachedir/$file")) {
      die "could not open $cachedir/$file: $!";
    }

    $data =  do { local $/; <FILE> };

    close(FILE);

    $record = $pdb->findRecordByID($file);

    if(defined($record)) {
      if(defined($record->{data})
	 && $record->{data} eq $data) {
	print "${prefix}record $record->{id} unchanged\n" if $debug;
	next;
      }
      print "${prefix}updating $record->{id}\n" if $debug;
    } else {
      print "${prefix}adding $file\n" if $debug;
      $record = $pdb->append_Record();
      $record->{id} = $file;
    }

    $record->{data} = $data;
    $record->{attributes}{dirty} = 1;
    $record->{attributes}{Dirty} = 1;
    $record->{category} = 0;
    ++$modified;
  }

  if($modified) {
    print "${prefix}PDB was modified, updating ctime\n" if $debug;
    my $curtime = time();
    $pdb->{ctime} = $curtime;
    $pdb->{mtime} = $curtime;
  }
}

sub doFetch {
  update_home(
	      PDB => $ColdSync::PDB,
	      File => $HEADERS{File},
	      Cache => $HEADERS{Cache},
	      Verbose => $HEADERS{Verbose},
	      Prefix => '100 '
	     );

  return 1;
}

Palm::PDB::RegisterPDBHandlers('Palm::Raw',
			       [ 'Plkr', 'Data' ],
			      );

ConduitMain(
	    'fetch' => \&doFetch,
	   );