# HG changeset patch # User Matti Hamalainen # Date 1417070872 -7200 # Node ID 5d7e525b0eb580ac7b9dd976e0dc692701082183 # Parent dfa1277786c1283546a4df7a261cd27d11209cde Moar work. diff -r dfa1277786c1 -r 5d7e525b0eb5 faptool.php --- a/faptool.php Thu Nov 27 08:27:58 2014 +0200 +++ b/faptool.php Thu Nov 27 08:47:52 2014 +0200 @@ -6,10 +6,21 @@ stCheckCLIExec(); +function wtExec($exe, $args) +{ + echo "@@EXEC: ".$exe." ".$args."\n"; + if (passthru($exe." ".$args) == 0) + { + echo "Error executing ".$exe.":\n".$args."\n"; + return FALSE; + } + return TRUE; +} + function wtExecOrDie($exe, $args) { - echo "EXEC: ".$exe." ".$args."\n"; - //passthru($exe." ".$args) == 0 or die("Error executing ".$exe.":\n".$args); + if (wtExec($exe, $args) === false) + die(); } @@ -80,7 +91,7 @@ $sduration = intval(stGetSetting("sampleDuration")); $schannels = intval(stGetSetting("sampleChannels")); - wtExecOrDie( + return wtExec( "/usr/local/bin/openmpt123" , "--quiet --render ". @@ -100,7 +111,7 @@ foreach ($opts as $okey => $oval) $optStr .= $okey." ".$oval." "; - wtExecOrDie( + return wtExec( "/usr/local/bin/avconv", "-y -t ".intval($sduration)." ". "-i ".escapeshellarg($inFilename). @@ -117,16 +128,11 @@ } -function wtScanArchive($compo, $efile, $filename) +function wtUnpackArchiveTo($atype, $filename, $path) { - global $setEntryPath; - - $path = stMakePath(FALSE, FALSE, array($setEntryPath, "UNPACKS", $filename)); - - echo "Attempting to scan archive file '".$filename."' ...\n"; - // Check file type before doing anything - switch ($efile["id"]) + echo "Preparing to unpack archive file '".$filename."' ...\n"; + switch ($atype) { case "LHA": $exe = "/usr/bin/lha"; @@ -144,7 +150,7 @@ break; default: - echo "Unsupported archive file type: ".$efile["id"]."\n"; + echo "Unsupported archive file type: ".$atype."\n"; return FALSE; } @@ -153,10 +159,26 @@ stMakeDir($path, 0700); if (!is_dir($path) || chdir($path) === false) - die("Failed to chdir to ".$path."\n"); + { + echo "Failed to chdir to '".$path."', can't unpack archive.\n"; + return FALSE; + } // Unpack archive - wtExecOrDie($exe, $args); + return wtExec($exe, $args); +} + + +function wtScanArchive($efile, $filename) +{ + global $setEntryPath; + + $path = stMakePath(FALSE, FALSE, array($setEntryPath, "UNPACKS", $filename)); + + echo "Attempting to scan archive file '".$filename."' ...\n"; + + if (wtUnpackArchiveTo($efile["filetype"], $filename, $path)) === false) + return FALSE; // Scan through files ... $dir = opendir($path); @@ -166,6 +188,7 @@ closedir($dir); wtPurgeDir($path); + return TRUE; } @@ -263,7 +286,8 @@ function stInitializeDirs() { - global $setEntryPath, $setPreviewPath, $setThumbDir, + global + $setEntryPath, $setPreviewPath, $setThumbDir, $setEntryPathPerms, $setPrevPathPerms; echo "Checking for missing directories ...\n";