]> gitweb @ CieloNegro.org - sugar.git/blob - tools/export.pl
Auto commit by The Sugar System.
[sugar.git] / tools / export.pl
1 use strict;
2 use warnings;
3 use Smart::Comments;
4 use lib 'tools';
5 require 'utils.pl';
6 use File::Spec;
7 use File::Compare qw(compare);
8 use File::Copy qw(copy);
9 use File::Path qw(mkpath);
10
11 sub main {
12     while (defined(my $arg = <>)) {
13         chomp $arg;
14
15         my $rel   = File::Spec->file_name_is_absolute($arg)
16                   ? File::Spec->abs2rel($arg, $ENV{HOME})
17                   : $arg;
18         my $abs   = File::Spec->rel2abs($rel, $ENV{HOME});
19         my $saved = rel2saved($rel);
20
21         if (!-e $saved) {
22             print "SKIP: $rel is not in the repository.\n";
23             next;
24         }
25         elsif (-e $abs) {
26             if (compare($abs, $saved) == 0) {
27                 print "SKIP: $rel is identical to the copy in the repository.\n";
28             }
29             else {
30                 print "SKIP: $rel is different from the copy in the repository.\n";
31             }
32         }
33         else {
34             print "Copying $saved to $abs...\n";
35             my @path = File::Spec->splitdir($abs);
36             pop @path;
37             mkpath(File::Spec->catdir(@path));
38             copy($saved, $abs) or die $!;
39         }
40     }
41 }
42
43 main();