Add mounted source check to avoid being deleted unexpectlly, 580
authorZhang Qiang <qiang.z.zhang@intel.com>
Mon, 28 Jan 2013 16:11:09 +0000 (11:11 -0500)
committerZhang Qiang <qiang.z.zhang@intel.com>
Mon, 28 Jan 2013 19:01:05 +0000 (14:01 -0500)
Change-Id: Ifca30dcfb1c0f774b7715bd1e8aaffa78e661e02

depanneur

index ed4fb57c2e793522fe3e55c7ad8fe655aae6337f..e69e34fb7d7b555c4eb8624f296da48cd0a4832e 100755 (executable)
--- a/depanneur
+++ b/depanneur
@@ -1048,6 +1048,25 @@ sub safe_umount {
     }
 }
 
+sub mount_source_check {
+    my $build_root = canonpath(shift);
+
+    my (undef, $tmp_file) = tempfile(CLEANUP=>1, OPEN => 0);
+    if (my_system("mount -l >$tmp_file 2>/dev/null") == 0) {
+        open my $file, '<', $tmp_file or die $!;
+        while (<$file>) {
+            chomp;
+            next if ($_ !~ /$build_root/);
+            my @mount_info= split(' ', $_);
+            if (-e $mount_info[0] and -e "$mount_info[0]/.git"){
+                error("$mount_info[0] has been mounted to $mount_info[2]. " .
+                      "Please unmount it manually to avoid being deleted " .
+                      "unexpectly.");
+            }
+        }
+    }
+}
+
 sub build_package {
     my ($name, $thread, $index) = @_;
     use vars qw(@package_repos);
@@ -1496,6 +1515,10 @@ $SIG{'ALRM'} = sub {
 # trigger 'ALRM' immediately
 kill 'ALRM', $$;
 
+for(my $i = 0; $i < $MAX_THREADS; $i++) {
+    mount_source_check("$scratch_dir.$i");
+}
+
 # only one package need to be built, do it directly
 if ($noinit == 1 || $incremental == 1) {
     my $ret = 0;
@@ -1535,6 +1558,7 @@ if ($debug) {
     }
 }
 
+
 while (! $TERM) {
     my @order = ();
     my @o = ();