perl

A quick dirty job to synchronize Picasa folders through iCloud

I use Picasa a lot even Google stopped developing it.  I put the Picasa folder on Desktop so it can be replicated by iCloud which makes that I can have the same files and folders on both office and home mac.  Recently, I found that the modification I made on one mac can’t be synchronized to another, and vice versa.
The issue is that Picasa does not REALLY modify the picture, it put the modification in a hidden file called .picasa.ini under every folder, which won’t be replicated by iCloud.  The solution is to create a none hidden file I named picasa.ini duplicated from .picasa.ini , then delete the original .picasa then create a symbol link .picasa.ini to picasa.ini .
The following Perl code does the batch job, a quick dirty one.  It will test the folder to see whether .picasa.ini exists, once it has .picasa.ini means it’s a Picasa folder.  Then it tests the picasa.ini file, it will duplicate .picasa.ini once it doesn’t exist.  Then do the following jobs.

#!/usr/bin/perl
$dir_to_process = ".";
opendir DIR, $dir_to_process
    or die "Cannot open $dir_to_process: $!";
foreach $file (readdir DIR) {
    if (-d $file) {
        print "$file  is a directory\n";
        $file_dot=".picasa.ini";
        $file_nodot="picasa.ini";
        opendir PICASA, $file;
        foreach $ffile (readdir PICASA) {
            if ($ffile eq  $file_dot) {
                print ".picasa.ini found in $file\n";
                $mark_dot_picasa = 1;
                if (-l $file."/".$ffile) {
                    print ".picasa.ini is already a symbol link.\n";
                    $mark_islink = 1;
           } else {
                    print ".picasa.ini isn't a symbol link, need to do something.\n";
                }
                if ($ffile eq $file_nodot) {
                    print "picasa.ini found in $file\n";
           $mark_nodot_picasa=1;
                }
          }
   }
        if (($mark_nodot_picasa) && ($mark_islink)) {
            print "This folder was already processed.\n";
            print "Nothing need to be touched.\n\n";
        }
        if (!$mark_dot_picasa) {
            print "This is not a picasa folder.\n\n";
        }
        $_ = $file;
        ~s/\'/\\\'/g;
        ~s/\ /\\\ /g;
        ~s/\&/\\\&/g;
        ~s/\@/\\\@/g;
        $file = $_;
        if (($mark_dot_picasa)&&(!($mark_islink))) {
            if (!($mark_nodot_picasa)) {
                print "Move .picasa.ini to picasa.ini\n";
                system ("cp $file/.picasa.ini $file/picasa.ini.backup");
                system ("mv $file/.picasa.ini $file/picasa.ini");
                print ".picasa is backup.\n";
                print "Created picasa.ini.\n";
            } else {
                system ("rm $file/.picasa.ini");
                print "picasa.ini already exists, just remove none symbol link .picasa.ini.";
            }
            system ("ln -s picasa.ini $file/.picasa.ini");
            print "Symbol linked .picasa to picasa.ini.\n";
        }
    }
    if (($mark_dot_picasa)&&($mark_nodot_picasa)&&(!($mark_islink)))  {
        print ".picasa.ini and picasa.ini exist and .picasa is not a symbol link, delete .picasa.ini and create link.\n";
    }
    $mark_dot_picasa = 0;
    $mark_nodot_picasa = 0;
    $mark_islink = 0;
    print "\n";
    closedir PICASA;
}
closedir DIR;

Leave a Reply

Your email address will not be published. Required fields are marked *