threads / patch / 6646

patchgit-archimport: initial import needs empty directory

Subject: [PATCH] git-archimport: initial import needs empty directory

## tl;dr

One message between Feb 3, 2007 and Feb 3, 2007. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Gerrit Pape· Feb 3, 2007, 22:38 UTC · lore
Hi, please see http://bugs.debian.org/400508:
> git-archimport deletes the directory tree in the current working
> directory during the initial import. The documentation has a sentence
> saying that an empty directory is expected but this can be dangerous
> for people not familiar with the tool.

git-archimport should better refuse to start an initial import if the current directory is not empty.

Signed-off-by: Gerrit Pape <pape@smarden.org>
---
 git-archimport.perl |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
Show changes to git-archimport.perl +9 −0
diff --git a/git-archimport.perl b/git-archimport.perl
index 2e15781..66aaeae 100755
--- a/git-archimport.perl
+++ b/git-archimport.perl
@@ -95,6 +95,15 @@ $ENV{'TMPDIR'} = $opt_t if $opt_t; # $ENV{TMPDIR} will affect tempdir() calls:
 my $tmp = tempdir('git-archimport-XXXXXX', TMPDIR => 1, CLEANUP => 1);
 $opt_v && print "+ Using $tmp as temporary directory\n";
 
+unless (-d $git_dir) { # initial import needs empty directory
+    opendir DIR, '.' or die "Unable to open current directory: $!\n";
+    while (my $entry = readdir DIR) {
+        $entry =~ /^\.\.?$/ or
+            die "Initial import needs an empty current working directory.\n"
+    }
+    closedir DIR
+}
+
 my %reachable = ();             # Arch repositories we can access
 my %unreachable = ();           # Arch repositories we can't access :<
 my @psets  = ();                # the collection
-- 
1.4.4.4

← back to recent threads