]> gitweb @ CieloNegro.org - sugar.git/blobdiff - tools/export.pl
tools/export.pl
[sugar.git] / tools / export.pl
diff --git a/tools/export.pl b/tools/export.pl
new file mode 100644 (file)
index 0000000..46f50c0
--- /dev/null
@@ -0,0 +1,39 @@
+use strict;
+use warnings;
+use Smart::Comments;
+use lib 'tools';
+require 'utils.pl';
+use File::Spec;
+use File::Compare;
+use File::Copy;
+
+sub main {
+    while (defined(my $arg = <>)) {
+        chomp $arg;
+
+        my $rel   = File::Spec->file_name_is_absolute($arg)
+                  ? File::Spec->abs2rel($arg, $ENV{HOME})
+                  : $arg;
+        my $abs   = File::Spec->rel2abs($rel, $ENV{HOME});
+        my $saved = rel2saved($rel);
+
+        if (!-e $saved) {
+            print "SKIP: $rel is not in the repository.\n";
+            next;
+        }
+        elsif (-e $abs) {
+            if (compare($abs, $saved) == 0) {
+                print "SKIP: $rel is identical to the copy in the repository.\n";
+            }
+            else {
+                print "SKIP: $rel is different from the copy in the repository.\n";
+            }
+        }
+        else {
+            print "Copying $saved to $abs...\n";
+            copy($saved, $abs) or die $!;
+        }
+    }
+}
+
+main();