--- marksync-o 2004-02-24 16:16:08.000000000 +0000 +++ marksync 2004-02-25 20:05:48.195465960 +0000 @@ -16,11 +16,12 @@ ); sub die_usage() { - die("usage: gnus_maildir_sync {--f2m|--m2f} nnmaildir-directory"); + die("usage: marksync {--f2m|--m2f} nnmaildir-directory"); } sub die_err(@) { die('unable to ', @_, ': ', $!, "\n"); } sub die_open($ ) { die_err('open ', $_[0]); } sub die_link($$) { die_err('link ', $_[0], ' to ', $_[1]); } +sub die_mkdir($) { die_err('mkdir ', $_[0]); } @ARGV==2 or die_usage(); my $mode=$ARGV[0]; @@ -28,7 +29,19 @@ sub file_exists() { return ($! != Errno::ENOENT); } +sub mkdirhier($) { + my $dir=$_[0]; + unless (-d $dir) { + my $pdir=$dir; + $pdir=~s:/[^/]+$::; + if ($dir=~/\//) { &mkdirhier($pdir); } + if ($dir ne '') { mkdir($dir) or die_mkdir($dir); } + } +} + sub do_create($ ) { + $_[0]=~/(.*)\/.*/; + mkdirhier($1); my $file=IO::File->new(); $file->open($_[0], O_WRONLY|O_CREAT, 0600) or die_open($_[0]); $file->close(); @@ -45,7 +58,7 @@ my @files=readdir($dir); closedir($dir); @files=grep(/[^.]/, @files); - if ($fullpath) { @files=map($dirpath.$_, @files); } + if ($fullpath) { @files=map($dirpath.'/'.$_, @files); } return @files; } @@ -61,7 +74,6 @@ if ($info!~/^:2,/) { next; } if ($mode eq '--m2f') { # Update the maildir flags my $new_flags=''; - if (index($info, 'D')>=0) { $new_flags.='D'; } foreach my $map (@mapping) { my ($flag, $mark)=@$map; my $markpath=$maildir.'/.nnmaildir/marks/'.$mark.'/'.$uniq; @@ -85,9 +97,9 @@ if (index($info, $flag)>=0) { my $linkpath=$markdir.'/:'; if (link($linkpath, $markpath) or $!==Errno::EEXIST) { next; } - if (not file_exists()) { create_file($linkpath); } + if (not file_exists()) { do_create($linkpath); } elsif ($!==Errno::EMLINK) { - create_file($linkpath.'{new}'); + do_create($linkpath.'{new}'); do_rename($linkpath.'{new}', $linkpath); } else { die_link($linkpath, $markpath); } link($linkpath, $markpath) or $!==Errno::EEXIST