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

Re: [coldsync-hackers] record attributes madness



On Saturday 11 October 2003 15:36, Christophe Beauregard wrote:

> Because of the larger installed base and the fact that it's not as
> closely tied to ColdSync as ColdSync::SPC (and, in fact, is used
> independently in many cases), changing Palm::PDB (even with version
> number increments) is probably the Wrong Thing to do. Especially if, as
> you suggest later, Palm::PDB/pdb.h better reflect reality.
>
> > 	I think the best solution might be to find those sets of
> > identifiers that refer to the same flags ("Busy" and "deleted",
> > "Secret" and "private", etc.), and issue a warning in Palm::PDB::Write
> > if they are used. (I'd love to check for those at compile-time, but
> > can't think of any way to do so.) Perhaps add a flag so that
> > 	use Palm::PDB("sdk_attrib_id_compat");
> > doesn't issue warnings.
>
> Given that the PalmOS 5+ attributes names are newer and probably aren't
> as heavily used, it might be worth just dropping them entirely and
> warning when they're seen in any records.

Since I brought up the whole subject (and my wife is monopolizing the 
television while she recovers from surgery), I figured I'd have a quick go 
at a fix.

See the attached patches.

The gist is as follows:
in palm-perl-attributes.patch:
- Palm::PDB doesn't set any of the OS5 flags and warns when it encounters 
them in a record it's supposed to write. I don't see any reason to make 
warnings optional; if someone's got a piece of code that doesn't know that 
'Busy' means 'deleted', they should probably fix it.

in coldsync-attributes.patch:
- ColdSync::SPC: s/deleted/expunged/, s/busy/deleted/, s/secrete/private/, 
and s/archived/archive/.

- ColdSync::PDB: remove any reference to the OS 5 attributes.

- Assorted other changes: fix conduits

c.
? coldsync/Make.rules
? coldsync/autom4te.cache
? coldsync/config.h
? coldsync/config.log
? coldsync/config.status
? coldsync/configure
? coldsync/doc/version.texi
Index: coldsync/conduits/mbox-inbox
===================================================================
RCS file: /var/lib/cvs/coldsync/conduits/mbox-inbox,v
retrieving revision 1.1
diff -u -r1.1 mbox-inbox
--- coldsync/conduits/mbox-inbox	28 Jun 2003 14:30:24 -0000	1.1
+++ coldsync/conduits/mbox-inbox	11 Oct 2003 23:21:04 -0000
@@ -129,11 +129,9 @@
 	# skip over deleted messages
 	next if $message->{'status'} =~ /d/;
 
-	my $record = $PDB->new_Record;
+	my $record = $PDB->new_Record;	# initially dirty
 
 	$record->{category} = $catno;
-	$record->{_seen} = 1;
-	$record->{attributes}{dirty} = 1;	# XXX: is this needed?
 
 	my ($second, $minute, $hour, $mday, $mon, $year, $wday, $yday)
 		= gmtime($message->{'timestamp'});
Index: coldsync/conduits/send-mail-2
===================================================================
RCS file: /var/lib/cvs/coldsync/conduits/send-mail-2,v
retrieving revision 1.1
diff -u -r1.1 send-mail-2
--- coldsync/conduits/send-mail-2	28 Jun 2003 14:30:24 -0000	1.1
+++ coldsync/conduits/send-mail-2	11 Oct 2003 23:21:04 -0000
@@ -135,7 +135,8 @@
 
 while (my $record = $db->nextRecInCategory($catno)) {
 	next if $record->{'attributes'}{'deleted'};
-	next if $record->{'attributes'}{'archived'};
+	next if $record->{'attributes'}{'archive'};
+	next if $record->{'attributes'}{'expunged'};
 
 	unless (sendmail_record($record)) {
 		print "301 sendmail failed: $!";
Index: coldsync/conduits/zire71-photo
===================================================================
RCS file: /var/lib/cvs/coldsync/conduits/zire71-photo,v
retrieving revision 1.2
diff -u -r1.2 zire71-photo
--- coldsync/conduits/zire71-photo	25 Jun 2003 19:49:04 -0000	1.2
+++ coldsync/conduits/zire71-photo	11 Oct 2003 23:21:04 -0000
@@ -38,7 +38,8 @@
 	while (my $raw = dlp_ReadNextModifiedRec($dbh))
 	{
 		next if $raw->{'attributes'}{'deleted'};
-		next if $raw->{'attributes'}{'archived'};
+		next if $raw->{'attributes'}{'archive'};
+		next if $raw->{'attributes'}{'expunged'};
 
 		my $thumb = Palm::ZirePhoto->ParseRecord(%{$raw});
 
Index: coldsync/perl/ColdSync/ColdSync/PDB.pm
===================================================================
RCS file: /var/lib/cvs/coldsync/perl/ColdSync/ColdSync/PDB.pm,v
retrieving revision 1.2
diff -u -r1.2 PDB.pm
--- coldsync/perl/ColdSync/ColdSync/PDB.pm	10 Oct 2003 11:03:29 -0000	1.2
+++ coldsync/perl/ColdSync/ColdSync/PDB.pm	11 Oct 2003 23:21:05 -0000
@@ -172,23 +172,20 @@
 {
 	my $record = shift;
 
-	# snarfed from Palm::PDB
 	my $attributes = 0;
-	if ($record->{attributes}{expunged} || $record->{attributes}{deleted}) {
+	if ($record->{attributes}{archive})
+	{
+		# ensure it's deleted, sanely
+		$record->{attributes}{deleted} = 1;
+		$record->{attributes}{expunged} =1;
+
 		# archive during next sync
 		$attributes |= 0x08 if $record->{attributes}{archive};
-	} else {
-		$attributes = ($record->{category} & 0x0f);
 	}
 	$attributes |= 0x80 if $record->{attributes}{expunged};
 	$attributes |= 0x40 if $record->{attributes}{dirty};
 	$attributes |= 0x20 if $record->{attributes}{deleted};
 	$attributes |= 0x10 if $record->{attributes}{private};
-
-	$attributes |= 0x80 if $record->{'attributes'}{'Delete'};
-	$attributes |= 0x40 if $record->{'attributes'}{'Dirty'};
-	$attributes |= 0x20 if $record->{'attributes'}{'Busy'};
-	$attributes |= 0x10 if $record->{'attributes'}{'Secret'};
 
 	return $attributes;
 }
Index: coldsync/perl/ColdSync/ColdSync/SPC.pm
===================================================================
RCS file: /var/lib/cvs/coldsync/perl/ColdSync/ColdSync/SPC.pm,v
retrieving revision 1.25
diff -u -r1.25 SPC.pm
--- coldsync/perl/ColdSync/ColdSync/SPC.pm	5 Oct 2003 17:51:56 -0000	1.25
+++ coldsync/perl/ColdSync/ColdSync/SPC.pm	11 Oct 2003 23:21:05 -0000
@@ -1153,19 +1153,19 @@
 			 'data',
 			} = unpack("N n n C C a*", $_->{'data'});
 
-			$retval->{'attributes'}{'deleted'} =
+			$retval->{'attributes'}{'expunged'} =
 				$retval->{'attrs'} & 0x80 ? 1 : 0;
 
 			$retval->{'attributes'}{'dirty'} =
 				$retval->{'attrs'} & 0x40 ? 1 : 0;
 
-			$retval->{'attributes'}{'busy'} =
+			$retval->{'attributes'}{'deleted'} =
 				$retval->{'attrs'} & 0x20 ? 1 : 0;
 
-			$retval->{'attributes'}{'secret'} =
+			$retval->{'attributes'}{'private'} =
 				$retval->{'attrs'} & 0x10 ? 1 : 0;
 
-			$retval->{'attributes'}{'archived'} =
+			$retval->{'attributes'}{'archive'} =
 				$retval->{'attrs'} & 0x08 ? 1 : 0;
 
 			my $recsize = length($retval->{'data'});
@@ -1201,11 +1201,11 @@
 	$record->{'attrs'}
 	$record->{'category'}
 	$record->{'data'}
-	$record->{'attributes'}{'deleted'}
+	$record->{'attributes'}{'expunged'}
 	$record->{'attributes'}{'dirty'}  
-	$record->{'attributes'}{'busy'}   
-	$record->{'attributes'}{'secret'} 
-	$record->{'attributes'}{'archived'}
+	$record->{'attributes'}{'deleted'}   
+	$record->{'attributes'}{'private'} 
+	$record->{'attributes'}{'archive'}
 
 =cut
 #'
@@ -1242,11 +1242,11 @@
 	$record->{'attrs'}
 	$record->{'category'}
 	$record->{'data'}
-	$record->{'attributes'}{'deleted'}
+	$record->{'attributes'}{'expunged'}
 	$record->{'attributes'}{'dirty'}  
-	$record->{'attributes'}{'busy'}   
-	$record->{'attributes'}{'secret'} 
-	$record->{'attributes'}{'archived'}
+	$record->{'attributes'}{'deleted'}   
+	$record->{'attributes'}{'private'} 
+	$record->{'attributes'}{'archive'}
 
 =cut
 #'
? palm-perl/Makefile
? palm-perl/blib
? palm-perl/pm_to_blib
Index: palm-perl/Palm/PDB.pm
===================================================================
RCS file: /var/lib/cvs/palm-perl/Palm/PDB.pm,v
retrieving revision 1.32
diff -u -r1.32 PDB.pm
--- palm-perl/Palm/PDB.pm	10 Oct 2003 11:01:49 -0000	1.32
+++ palm-perl/Palm/PDB.pm	11 Oct 2003 23:21:22 -0000
@@ -636,13 +636,6 @@
 		$entry->{attributes}{deleted} = 1 if $attributes & 0x20;
 		$entry->{attributes}{private} = 1 if $attributes & 0x10;
 
-		# Attribute names as of PalmOS 5.0 ( see /Core/System/DataMgr.h )
-
-		$entry->{'attributes'}{'Delete'}	= 1 if $attributes & 0x80;
-		$entry->{'attributes'}{'Dirty'}		= 1 if $attributes & 0x40;
-		$entry->{'attributes'}{'Busy'}		= 1 if $attributes & 0x20;
-		$entry->{'attributes'}{'Secret'}	= 1 if $attributes & 0x10;
-
 		$entry->{id} =	($id[0] << 16) |
 				($id[1] << 8)  |
 				 $id[2];
@@ -1020,27 +1013,37 @@
 			# Get all the stuff that goes in the index, as
 			# well as the record data.
 			$attributes = 0;
-			if ($record->{attributes}{expunged} ||
-			    $record->{attributes}{deleted})
+			if (exists $record->{attributes})
+			{
+				if ($record->{attributes}{expunged} ||
+					 $record->{attributes}{deleted})
+				{
+					$attributes |= 0x08
+						if $record->{attributes}{archive};
+				} else {
+					$attributes = ($record->{category} & 0x0f);
+				}
+				$attributes |= 0x80
+					if $record->{attributes}{expunged};
+				$attributes |= 0x40
+					if $record->{attributes}{dirty};
+				$attributes |= 0x20
+					if $record->{attributes}{deleted};
+				$attributes |= 0x10
+					if $record->{attributes}{private};
+
+				warn( "Bogus record attribute 'Delete'" )
+					if exists $record->{'attributes'}{'Delete'};
+				warn( "Bogus record attribute 'Dirty'" )
+					if exists $record->{'attributes'}{'Dirty'};
+				warn( "Bogus record attribute 'Busy'" )
+					if exists $record->{'attributes'}{'Busy'};
+				warn( "Bogus record attribute 'Secret'" )
+					if exists $record->{'attributes'}{'Secret'};
+			} else
 			{
-				$attributes |= 0x08
-					if $record->{attributes}{archive};
-			} else {
 				$attributes = ($record->{category} & 0x0f);
 			}
-			$attributes |= 0x80
-				if $record->{attributes}{expunged};
-			$attributes |= 0x40
-				if $record->{attributes}{dirty};
-			$attributes |= 0x20
-				if $record->{attributes}{deleted};
-			$attributes |= 0x10
-				if $record->{attributes}{private};
-
-			$attributes |= 0x80 if $record->{'attributes'}{'Delete'};
-			$attributes |= 0x40 if $record->{'attributes'}{'Dirty'};
-			$attributes |= 0x20 if $record->{'attributes'}{'Busy'};
-			$attributes |= 0x10 if $record->{'attributes'}{'Secret'};
 
 			$id = $record->{id};
 
@@ -1250,10 +1253,10 @@
 Creates a new record, with the bare minimum needed:
 
 	$record->{'category'}
-	$record->{'attributes'}{'Dirty'}
+	$record->{'attributes'}{'dirty'}
 	$record->{'id'}
 
-The ``Dirty'' attribute is originally set, since this function will
+The ``dirty'' attribute is originally set, since this function will
 usually be called to create records to be added to a database.
 
 C<new_Record> does B<not> add the new record to a PDB. For that,
@@ -1273,12 +1276,7 @@
 	# Initialize the record
 	$retval->{'category'} = 0;	# Unfiled, by convention
 	$retval->{'attributes'} = {
-#		expunged	=> 0,
 		dirty		=> 1,	# Note: originally dirty
-		'Dirty'		=> 1,
-#		deleted		=> 0,
-#		private		=> 0,
-#		archive         => 0,
 	};
 	$retval->{'id'} = 0;		# Initially, no record ID
 
@@ -1315,7 +1313,6 @@
 
 		foreach $record (@{$self->{records}})
 		{
-			return 1 if $record->{'attributes'}{'Dirty'};
 			return 1 if $record->{'attributes'}{'dirty'};
 		}
 	}