Commit 86a16097 authored by Marc Egger's avatar Marc Egger
Browse files

Path: set cwdToApp after every chdir

parent a2800b04
Pipeline #4073 passed with stages
in 3 minutes and 50 seconds
......@@ -71,8 +71,9 @@ class Delete {
// Take care the necessary target directories exist.
$cwd = getcwd();
$cwdToApp = Path::cwdToApp();
$sitePath = Path::absoluteApp();
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath, '')) {
throw new \UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_TO_DEVELOPER => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
ERROR_IO_CHDIR);
......@@ -93,7 +94,7 @@ class Delete {
}
HelperFile::chdir($cwd);
HelperFile::chdir($cwd, $cwdToApp);
}
/**
......
......@@ -247,19 +247,23 @@ class HelperFile {
}
/**
* PHP System function: chdir() with QFQ exception
* PHP System function: chdir() with QFQ exception.
*
* @param $cwd
* @param $newCwd
* @param string $pathNewCwdToApp Path from the new cwd to the App directory.
* @return string
* @throws \CodeException
* @throws \UserFormException
*/
public static function chdir($cwd) {
public static function chdir($newCwd, string $pathNewCwdToApp) {
if (false === @chdir($cwd)) {
$msg = self::errorGetLastAsString() . " - chdir($cwd)";
if (false === @chdir($newCwd)) {
$msg = self::errorGetLastAsString() . " - chdir($newCwd)";
throw new \UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'chdir failed', ERROR_MESSAGE_TO_DEVELOPER => $msg]), ERROR_IO_CHDIR);
}
Path::setMainPaths($pathNewCwdToApp);
return true;
}
......@@ -361,15 +365,18 @@ class HelperFile {
* @param string $pathFileName Path with Filename
* @param bool|int $chmodDir false if not explicit set
* @throws \UserFormException
* @throws \CodeException
*/
public static function mkDirParent($pathFileName, $chmodDir = false) {
$path = "";
$cwd = '';
$cwdToApp = '';
// Leading '/' will be removed - chdir to / to still use correct path
if ($pathFileName[0] == '/') {
$cwd = getcwd();
self::chdir('/');
$cwdToApp = Path::cwdToApp();
self::chdir('/', Path::absoluteApp());
}
// Teile "Directory/File.Extension" auf
......@@ -408,7 +415,7 @@ class HelperFile {
}
if ($cwd != '') {
self::chdir($cwd);
self::chdir($cwd, $cwdToApp);
}
}
......
......@@ -94,6 +94,8 @@ class Path
public static function setMainPaths(string $cwdToApp)
{
self::setCwdToApp($cwdToApp);
// Only executed on first call:
self::findAppToProject();
self::findAbsoluteLog();
}
......@@ -391,6 +393,11 @@ class Path
*/
private static function findAbsoluteLog()
{
if (!is_null(self::$absoluteLog)) {
// only execute once
return;
}
// search log dir qfqProject/log
$absoluteLog = self::absoluteApp(self::appToProject(self::PROJECT_TO_LOG_DEFAULT));
if (file_exists($absoluteLog)) {
......@@ -415,6 +422,11 @@ class Path
*/
private static function findAppToProject()
{
if (!is_null(self::$appToProject)) {
// only execute once
return;
}
// does qfq.project.path.php exist? => read path
$cwdToProjectPathFile = self::cwdToApp(PROJECT_PATH_PHP_FILE);
if (HelperFile::isReadableException($cwdToProjectPathFile)) {
......
......@@ -544,7 +544,7 @@ class Download {
$filesCleanLater = array();
$workDir = Path::absoluteApp();
HelperFile::chdir($workDir);
HelperFile::chdir($workDir, '');
$downloadMode = $vars[DOWNLOAD_MODE];
......
......@@ -495,10 +495,10 @@ class Save {
// Upload - Take care the necessary target directories exist.
$cwd = getcwd();
$sitePath = Path::cwdToApp();
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
$cwdToApp = Path::cwdToApp();
if ($cwd === false || $cwdToApp === false || !HelperFile::chdir($cwdToApp, '')) {
throw new \UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_TO_DEVELOPER => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_TO_DEVELOPER => "getcwd() failed or SITE_PATH undefined or chdir('$cwdToApp') failed."]),
ERROR_IO_CHDIR);
}
......@@ -604,7 +604,7 @@ class Save {
}
// Clean up
HelperFile::chdir($cwd);
HelperFile::chdir($cwd, $cwdToApp);
// Only used in 'Simple Upload'
if (count($newValues) > 0) {
......@@ -781,7 +781,7 @@ class Save {
// Take care the necessary target directories exist.
$cwd = getcwd();
$sitePath = Path::absoluteApp();
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath, '')) {
throw new \UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_TO_DEVELOPER => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
ERROR_IO_CHDIR);
......@@ -1259,9 +1259,10 @@ class Save {
}
// Split PDF
HelperFile::chdir($tempDir);
$cwdToApp = Path::cwdToApp();
HelperFile::chdir($tempDir, $cwdToApp);
$output = Support::qfqExec($cmd, $rc);
HelperFile::chdir($cwd);
HelperFile::chdir($cwd, $cwdToApp);
if ($rc != 0) {
throw new \UserFormException(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment