Changeset 29891 for trunk/PS-IPP-Config/lib/PS/IPP/Config.pm
- Timestamp:
- Dec 1, 2010, 12:45:20 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/PS-IPP-Config/lib/PS/IPP/Config.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/PS-IPP-Config/lib/PS/IPP/Config.pm
r29748 r29891 1087 1087 } 1088 1088 1089 sub prepare_output 1090 { 1091 my $self = shift; # Configuration object 1092 my $name = shift; # Name of the filerule 1093 my $outroot = shift; # For replacing {OUTPUT} 1094 my $component = shift; # For replacing {CHIP.NAME} and {CELL.NAME} 1095 my $delete_existing = shift; # if file exists delete it 1096 my $r_error = shift; # reference to error code 1097 1098 die "prepare_output: invalid number of arguments" if !defined $r_error; 1099 1100 $$r_error = 0; 1101 1102 my $output = $self->filename($name, $outroot, $component); 1103 if (!$output) { 1104 # error message emitted by filename should be sufficient 1105 $$r_error = $PS_EXIT_CONFIG_ERROR; 1106 return undef; 1107 } 1108 1109 if (file_scheme($output) ne 'neb') { 1110 # non-nebulous file we're done 1111 if ($delete_existing) { 1112 if (!$self->file_delete($output)) { 1113 carp "failed to delete $output"; 1114 $$r_error = $PS_EXIT_SYS_ERROR; 1115 $output = undef; 1116 } 1117 } 1118 return $output; 1119 } 1120 1121 my $neb = $self->nebulous; 1122 if ($neb->storage_object_exists($output)) { 1123 if ($delete_existing) { 1124 # avoid dead instances by moving the file before deleting it. 1125 # append current time to form new name 1126 my $todelete; 1127 eval { 1128 # parse the key so that we can compute the new name 1129 require Nebulous::Key; 1130 }; 1131 if ($@) { 1132 carp "Can't find Nebulous::Key"; 1133 $$r_error = $PS_EXIT_CONFIG_ERROR; 1134 return undef; 1135 } 1136 eval { 1137 # parse the key so that we can compute the new name 1138 my $neb_key = Nebulous::Key::parse_neb_key($output); 1139 die "parse_neb_key failed" if !$neb_key; 1140 my $path = $neb_key->path; 1141 die "neb_key has no path" if !$path; 1142 my $ticks = time(); 1143 $todelete = "ipp_trash/$path.$ticks"; 1144 $neb->move($output, $todelete); 1145 }; 1146 if ($@) { 1147 carp "nebulous move failed for $output"; 1148 $output = undef; 1149 $$r_error = $PS_EXIT_SYS_ERROR; 1150 } 1151 if ($todelete) { 1152 eval { 1153 $neb->delete($todelete); 1154 }; 1155 if ($@) { 1156 carp "nebulous delete for $todelete failed. Ignoring.\n"; 1157 $$r_error = $PS_EXIT_SYS_ERROR; 1158 } 1159 } 1160 } else { 1161 # Make sure that there is only 1 instance. 1162 1163 eval { 1164 $neb->there_can_be_only_one($output); 1165 }; 1166 if ($@) { 1167 carp "nebulous there_can_be_only_one() failed for $output"; 1168 $output = undef; 1169 $$r_error = $PS_EXIT_SYS_ERROR; 1170 } 1171 } 1172 } 1173 return $output; 1174 } 1175 1176 # Cause a nebulous file to be replicated setting the user.copies value 1177 sub replicate_file 1178 { 1179 my $self = shift; 1180 my $file = shift; 1181 my $copies = shift; 1182 1183 if (file_scheme($file) ne 'neb') { 1184 carp "cannot replicate non-neulous file: $file"; 1185 return 0; 1186 } 1187 1188 if (!$copies) { 1189 $copies = 2; 1190 } 1191 1192 my $neb = $self->nebulous; 1193 eval { 1194 $neb->setxattr($file, 'user.copies', $copies, 'replace'); 1195 }; 1196 if ($@) { 1197 carp "failed to set user.copies for $file"; 1198 return 0; 1199 } 1200 1201 # XXX: if copies > 2 should we make more replicants here ? 1202 eval { 1203 $neb->replicate($file); 1204 }; 1205 if ($@) { 1206 carp "failed to replicate $file"; 1207 return 0; 1208 } 1209 return 1; 1210 } 1211 1212 1089 1213 # Return catdir for tessellation, from TESSELLATIONS within the site configuration 1090 1214 sub tessellation_catdir
Note:
See TracChangeset
for help on using the changeset viewer.
