Greetings, esteemed monks!

Been a while. The Briefcase isn't quite working well. The Briefcase is designed to be a 2-way sync and it also seems to be reporting some files with identical modification times as both having been updated separately.

The main person who coordinates the source files is also leery of one of the users accidentally modifying the files on his stick. While the execs aren't supposed to be able to write back to the source stuff, she's a little leery of it as the permissions are tricky.

As a result, I've gone ahead and re-written something from scratch. I use File::Compare to be sure that the files are indeed different or identical. I eschew using the modificaiton date because this more cumbersome process will detect corruption in the mirrored data. However that's a lot of overhead. Is there another way I could do it at least as quickly and with the same robustness? For example I could check modification time FIRST (some files presumably would fail this quicker test and thus the contents comparison would be moot), and that way I would only be comparing the files that didn't really change, probably (which would still be the majority). Also, would something like an MD5 sum be a good way to check difference without reading every single one into memory (ie be 99.9% as robust but faster)? Here's my code so far:

use strict; use File::Copy; use File::Find; use File::Compare; my $source="G:\\contingency\\"; my $dest="D:\\"; (-r $source) || die "Error: $source not readable\n"; (-e $dest) || die "Error: $dest (memory stick) does not exist--is you +r memory stick attached?\n"; # for the convenience of &wanted calls, including -eval statements: use vars qw/*name *dir *prune/; *name = *File::Find::name; *dir = *File::Find::dir; *prune = *File::Find::prune; sub wanted{}; sub wanted2{}; my $newdirs; my $newfiles; my $changedfiles; my $unchangedfiles; my $orphans; #Freshen up memory stick my $status1=find(\&wanted,$source); #..and then take care of orphans my $status1=finddepth(\&wanted2,$dest); my $totalfiles=$newdirs+$newfiles+$changedfiles+$unchangedfiles+$orpha +ns; print "Summary report: \n"; print "$totalfiles scanned.\n"; print "$newdirs new directories found and created.\n"; print "$newfiles new files found and copied.\n"; print "$changedfiles updated files copied.\n"; print "$unchangedfiles unchanged files ignored.\n"; print "$orphans orphans deleted from memory stick.\n"; sub wanted{ $dest=$name; $dest =~ s/G:/D:/; #sleep 3; if (-d $name){ print "$name\n"; if ( not -e $dest){ print "Making directory $dest: \n"; mkdir $dest; ++$newdirs; } } else{ print "comparing $name to: \n$dest\n....\n"; my $status=compare($name, $dest); #print "status of compare is $status.\n"; unless (!$status){ print "copying $name to memory stick \n($dest)\n......\n"; my $cstatus=copy($name, $dest); #print "status of copy is $cstatus.\n"; #copy returns 1 on success ($cstatus) || die "Copy failed with status $cstatus: $!\n"; if ($status==-1){ print "File is new on contingency site since last update.\n(compar +e returned $status: $!\n"; ++$newfiles; }else{ print "Version of file on memory stick was different(stale or alte +red).\n"; ++$changedfiles; } }else{ print "files are identical.\n"; ++$unchangedfiles; } } } sub wanted2{ my $status=1; $source=$name; $source =~ s/D:/G:/; if ( not -e $source){ ++$orphans; print "$name is an orphan"; if (-d $name){ $status=rmdir $name; }else{ $status=unlink $name; } #rmidr returns true on success; unlink returns number of files del +eted (should be 1) ($status) || warn "WARNING: Status of removal of $name is $status + : $!\n"; } }
Thoughts? T.

_________________________________________________________________________________

I like computer programming because it's like Legos for the mind.


In reply to Re: How to sync a UNC path to a USB memory stick in Windows? by OfficeLinebacker
in thread How to sync a UNC path to a USB memory stick in Windows? by OfficeLinebacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.