Revert "Improve error handling and reporting (partially resolves issue 695)"

This reverts commit 8ff15368ce.
This commit is contained in:
Thomas Keller 2011-06-04 01:14:22 +02:00
parent 8ff15368ce
commit 8693418d39

View File

@ -132,7 +132,7 @@ class IDF_Plugin_SyncMonotone
foreach ($confdir_contents as $content) { foreach ($confdir_contents as $content) {
if (!file_exists($confdir.$content)) { if (!file_exists($confdir.$content)) {
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('The configuration file "%s" is missing.'), $content __('The configuration file %s is missing.'), $content
)); ));
} }
} }
@ -141,16 +141,13 @@ class IDF_Plugin_SyncMonotone
$projectpath = sprintf($projecttempl, $shortname); $projectpath = sprintf($projecttempl, $shortname);
if (file_exists($projectpath)) { if (file_exists($projectpath)) {
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('The project path "%s" already exists.'), $projectpath __('The project path %s already exists.'), $projectpath
)); ));
} }
if (!@mkdir($projectpath)) { if (!mkdir($projectpath)) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('The project path "%s" could not be created: %s'), __('The project path %s could not be created.'), $projectpath
$projectpath, $err
)); ));
} }
@ -185,12 +182,9 @@ class IDF_Plugin_SyncMonotone
// //
$keydir = Pluf::f('tmp_folder').'/mtn-client-keys'; $keydir = Pluf::f('tmp_folder').'/mtn-client-keys';
if (!file_exists($keydir)) { if (!file_exists($keydir)) {
if (!@mkdir($keydir)) { if (!mkdir($keydir)) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('The key directory "%s" could not be created: %s'), __('The key directory %s could not be created.'), $keydir
$keydir, $err
)); ));
} }
} }
@ -244,24 +238,18 @@ class IDF_Plugin_SyncMonotone
foreach ($confdir_contents as $content) { foreach ($confdir_contents as $content) {
$filepath = $projectpath.'/'.$content; $filepath = $projectpath.'/'.$content;
if (substr($content, -1) == '/') { if (substr($content, -1) == '/') {
if (!@mkdir($filepath)) { if (!mkdir($filepath)) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('Could not create configuration directory "%s": %s'), __('Could not create configuration directory "%s"'), $filepath
$filepath, $err
)); ));
} }
continue; continue;
} }
if (substr($content, -3) != '.in') { if (substr($content, -3) != '.in') {
if (!@symlink($confdir.$content, $filepath)) { if (!symlink($confdir.$content, $filepath)) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
IDF_Scm_Exception(sprintf( IDF_Scm_Exception(sprintf(
__('Could not create symlink for configuration file "%s": %s'), __('Could not create symlink "%s"'), $filepath
$filepath, $err
)); ));
} }
continue; continue;
@ -276,12 +264,9 @@ class IDF_Plugin_SyncMonotone
// remove the .in // remove the .in
$filepath = substr($filepath, 0, -3); $filepath = substr($filepath, 0, -3);
if (@file_put_contents($filepath, $filecontents, LOCK_EX) === false) { if (file_put_contents($filepath, $filecontents, LOCK_EX) === false) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('Could not write configuration file "%s": %s'), __('Could not write configuration file "%s"'), $filepath
$filepath, $err
)); ));
} }
} }
@ -330,12 +315,9 @@ class IDF_Plugin_SyncMonotone
// FIXME: more sanity - what happens on failing writes? we do not // FIXME: more sanity - what happens on failing writes? we do not
// have a backup copy of usher.conf around... // have a backup copy of usher.conf around...
if (@file_put_contents($usher_config, $usher_rc, LOCK_EX) === false) { if (file_put_contents($usher_config, $usher_rc, LOCK_EX) === false) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('Could not write usher configuration file "%s": %s'), __('Could not write usher configuration file "%s"'), $usher_config
$usher_config, $err
)); ));
} }
@ -379,12 +361,9 @@ class IDF_Plugin_SyncMonotone
$write_permissions = implode("\n", $key_ids); $write_permissions = implode("\n", $key_ids);
$rcfile = $projectpath.'/write-permissions'; $rcfile = $projectpath.'/write-permissions';
if (@file_put_contents($rcfile, $write_permissions, LOCK_EX) === false) { if (file_put_contents($rcfile, $write_permissions, LOCK_EX) === false) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('Could not write write-permissions file "%s": %s'), __('Could not write write-permissions file "%s"'), $rcfile
$rcfile, $err
)); ));
} }
@ -405,12 +384,9 @@ class IDF_Plugin_SyncMonotone
} }
$read_permissions = IDF_Scm_Monotone_BasicIO::compile(array($stanza)); $read_permissions = IDF_Scm_Monotone_BasicIO::compile(array($stanza));
$rcfile = $projectpath.'/read-permissions'; $rcfile = $projectpath.'/read-permissions';
if (@file_put_contents($rcfile, $read_permissions, LOCK_EX) === false) { if (file_put_contents($rcfile, $read_permissions, LOCK_EX) === false) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('Could not write read-permissions file "%s": %s'), __('Could not write read-permissions file "%s"'), $rcfile
$rcfile, $err
)); ));
} }
@ -425,19 +401,17 @@ class IDF_Plugin_SyncMonotone
$serverRestartRequired = false; $serverRestartRequired = false;
if ($project->private && file_exists($projectfile) && is_link($projectfile)) { if ($project->private && file_exists($projectfile) && is_link($projectfile)) {
if (!@unlink($projectfile)) { if (!unlink($projectfile)) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
IDF_Scm_Exception(sprintf( IDF_Scm_Exception(sprintf(
__('Could not remove symlink "%s": %s'), $projectfile, $err __('Could not remove symlink "%s"'), $projectfile
)); ));
} }
$serverRestartRequired = true; $serverRestartRequired = true;
} else } else
if (!$project->private && !file_exists($projectfile)) { if (!$project->private && !file_exists($projectfile)) {
if (!@symlink($templatefile, $projectfile)) { if (!symlink($templatefile, $projectfile)) {
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('Could not create symlink "%s": %s'), $projectfile, $err __('Could not create symlink "%s"'), $projectfile
)); ));
} }
$serverRestartRequired = true; $serverRestartRequired = true;
@ -499,11 +473,8 @@ class IDF_Plugin_SyncMonotone
if ($keyname && $keyhash && if ($keyname && $keyhash &&
file_exists($keydir .'/'. $keyname . '.' . $keyhash)) { file_exists($keydir .'/'. $keyname . '.' . $keyhash)) {
if (!@unlink($keydir .'/'. $keyname . '.' . $keyhash)) { if (!@unlink($keydir .'/'. $keyname . '.' . $keyhash)) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('Could not delete client private key "%s": %s'), __('Could not delete client private key %s'), $keyname
$keyname, $err
)); ));
} }
} }
@ -534,12 +505,9 @@ class IDF_Plugin_SyncMonotone
// FIXME: more sanity - what happens on failing writes? we do not // FIXME: more sanity - what happens on failing writes? we do not
// have a backup copy of usher.conf around... // have a backup copy of usher.conf around...
if (@file_put_contents($usher_config, $usher_rc, LOCK_EX) === false) { if (file_put_contents($usher_config, $usher_rc, LOCK_EX) === false) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('Could not write usher configuration file "%s": %s'), __('Could not write usher configuration file "%s"'), $usher_config
$usher_config, $err
)); ));
} }
@ -630,13 +598,10 @@ class IDF_Plugin_SyncMonotone
$read_perms = IDF_Scm_Monotone_BasicIO::compile($parsed_read_perms); $read_perms = IDF_Scm_Monotone_BasicIO::compile($parsed_read_perms);
if (@file_put_contents($projectpath.'/read-permissions', if (file_put_contents($projectpath.'/read-permissions',
$read_perms, LOCK_EX) === false) { $read_perms, LOCK_EX) === false) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('Could not write read-permissions for project "%s": %s'), __('Could not write read-permissions for project "%s"'), $shortname
$shortname, $err
)); ));
} }
} }
@ -646,13 +611,11 @@ class IDF_Plugin_SyncMonotone
if (!in_array('*', $lines) && !in_array($mtn_key_id, $lines)) { if (!in_array('*', $lines) && !in_array($mtn_key_id, $lines)) {
$lines[] = $mtn_key_id; $lines[] = $mtn_key_id;
} }
if (@file_put_contents($projectpath.'/write-permissions', if (file_put_contents($projectpath.'/write-permissions',
implode("\n", $lines) . "\n", LOCK_EX) === false) { implode("\n", $lines) . "\n", LOCK_EX) === false) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('Could not write write-permissions file for project "%s": %s'), __('Could not write write-permissions file for project "%s"'),
$shortname, $err $shortname
)); ));
} }
@ -730,13 +693,10 @@ class IDF_Plugin_SyncMonotone
$read_perms = IDF_Scm_Monotone_BasicIO::compile($parsed_read_perms); $read_perms = IDF_Scm_Monotone_BasicIO::compile($parsed_read_perms);
if (@file_put_contents($projectpath.'/read-permissions', if (file_put_contents($projectpath.'/read-permissions',
$read_perms, LOCK_EX) === false) { $read_perms, LOCK_EX) === false) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('Could not write read-permissions for project "%s": %s'), __('Could not write read-permissions for project "%s"'), $shortname
$shortname, $err
)); ));
} }
} }
@ -751,13 +711,11 @@ class IDF_Plugin_SyncMonotone
continue; continue;
} }
} }
if (@file_put_contents($projectpath.'/write-permissions', if (file_put_contents($projectpath.'/write-permissions',
implode("\n", $lines) . "\n", LOCK_EX) === false) { implode("\n", $lines) . "\n", LOCK_EX) === false) {
$err = error_get_last();
$err = $err == null ? 'unknown error' : $err['message'];
throw new IDF_Scm_Exception(sprintf( throw new IDF_Scm_Exception(sprintf(
__('Could not write write-permissions file for project "%s": %s'), __('Could not write write-permissions file for project "%s"'),
$shortname, $err $shortname
)); ));
} }
@ -865,7 +823,7 @@ class IDF_Plugin_SyncMonotone
foreach ($scan as $subpath) { foreach ($scan as $subpath) {
$status |= self::_delete_recursive($subpath); $status |= self::_delete_recursive($subpath);
} }
$status |= @rmdir($path); $status |= rmdir($path);
return $status; return $status;
} }
} }