- Timestamp:
- Oct 2, 2009, 5:10:19 PM (17 years ago)
- Location:
- branches/eam_branches/20090820
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
DataStoreServer/scripts/dsprodtool (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20090820
- Property svn:mergeinfo changed
-
branches/eam_branches/20090820/DataStoreServer/scripts/dsprodtool
r24196 r25766 12 12 use PS::IPP::Metadata::Config; 13 13 use File::Copy; 14 15 use Term::ReadKey; 14 16 15 17 use PS::IPP::Config qw($PS_EXIT_SUCCESS … … 36 38 my $dsroot; 37 39 my $dbname; 40 my $dbpass; 38 41 39 42 my $add; … … 78 81 } else { 79 82 $product = $del; 83 if (! -t STDIN) { 84 die "cannot delete product from script\n"; 85 } 86 print "*** Delete the Data Store Product $product? ***\n"; 87 print "*** to delete $product answer YES, and give password ***\n"; 88 print "*** WARNING this action is permanant *** \n"; 89 print "Delete? (YES/[n]): "; 90 91 my $line = ReadLine(0); 92 chomp $line; 93 exit 1 if !$line or ($line ne "YES"); 94 95 print "password: "; 96 ReadMode('noecho'); 97 $line = ReadLine(0); 98 ReadMode('normal'); 99 print "\n"; 100 chomp $line; 101 $dbpass = $line; 80 102 } 81 103 … … 93 115 } 94 116 95 my $root_index_script = "$dsroot/index.txt ";117 my $root_index_script = "$dsroot/index.txt.template"; 96 118 if (!stat($root_index_script)) { 97 119 $err .= "Data Store not found at '$dsroot'.\n" … … 106 128 unless defined $dbname; 107 129 my $dbuser = metadataLookupStr($siteConfig, 'DS_DBUSER'); 108 my $dbpass = metadataLookupStr($siteConfig, 'DS_DBPASSWORD');130 $dbpass = metadataLookupStr($siteConfig, 'DS_DBPASSWORD') if !$dbpass; 109 131 exit ($PS_EXIT_CONFIG_ERROR) unless defined $dbserver and $dbname and $dbuser and $dbpass; 110 132 111 133 my $dsn = "DBI:mysql:host=$dbserver;database=$dbname"; 112 113 my $dbh = DBI->connect($dsn, $dbuser, $dbpass) or die "Cannot connect to server\n";114 115 134 116 135 my $product_dir = "$dsroot/$product"; … … 118 137 119 138 if ($del) { 139 my $dbh = DBI->connect($dsn, $dbuser, $dbpass) or die "Cannot connect to server\n"; 120 140 # 121 141 # delete product … … 129 149 } 130 150 my $prod_id = $prod_row->{prod_id}; 131 132 # if requested, remove the product directory133 if ($remove) {134 if (system "rm -r $product_dir") {135 die("failed to remove $product_dir");136 }137 } else {138 # otherwise just zap the index script139 unlink("$index_script_name");140 }141 151 142 152 … … 152 162 $dbh->do("DELETE from dsProduct where prod_id = $prod_id"); 153 163 164 print "Product $product deleted.\n"; 165 166 # if requested, remove the product directory 167 if ($remove) { 168 print "Removing files from $product.\n"; 169 if (system "rm -r $product_dir") { 170 die("failed to remove $product_dir"); 171 } 172 } else { 173 # otherwise just zap the index script 174 unlink("$index_script_name"); 175 } 176 154 177 exit 0; 155 178 … … 158 181 # add a new product 159 182 # 183 my $dbh = DBI->connect($dsn, $dbuser, $dbpass) or die "Cannot connect to server\n"; 184 160 185 my $stmt = $dbh->prepare("SELECT prod_id FROM dsProduct WHERE prod_name = \'$product\'"); 161 186 $stmt->execute(); … … 167 192 168 193 # set up the product directory 194 # if there is an old index file delete it 195 if (-e $index_script_name ) { 196 if (!unlink($index_script_name)) { 197 die("failed trying to remove old $index_script_name"); 198 } 199 } 169 200 if (! -e $product_dir) { 170 201 $we_created_dir = 1; … … 172 203 die("failed trying to make product directory $product_dir"); 173 204 } 174 } 175 if (-e $index_script_name ) {176 if (!unlink($index_script_name)) {177 die("failed trying to remove old $index_script_name");178 }179 } 205 } else { 206 # directory alrady exists make sure that it's empty 207 my @dirlist = glob("$product_dir/*"); 208 die ("existing product directory $product_dir is not empty") if scalar @dirlist; 209 } 210 180 211 if (!copy($root_index_script, $index_script_name)) { 181 212 print STDERR "failed trying to copy($root_index_script, $index_script_name)";
Note:
See TracChangeset
for help on using the changeset viewer.
