Sfoglia il codice sorgente

What is with the shell_exec stuff?

Zachary Kotlarek 12 anni fa
parent
commit
d2edd558f6
2 ha cambiato i file con 19 aggiunte e 9 eliminazioni
  1. 14 8
      scan.php
  2. 5 1
      upload.php

+ 14 - 8
scan.php

@@ -207,6 +207,7 @@ foreach ($FILES as $file) {
 		die('Unable to fetch entry for: ' . $file . "\n");
 	}
 
+
 	# Check the file type
 	if ($row['type'] != $TYPE) {
 		if ($DEBUG) {
@@ -220,9 +221,15 @@ foreach ($FILES as $file) {
 		continue;
 	}
 
+	# Grab the local file stats
+	$stat = @stat($path);
+	if ($stat === false) {
+		echo 'Unable to stat: ' . $path . "\n";
+		continue;
+	}
+
 	# Check the file mtime
-	$mtime = trim(shell_exec('stat -c "%Y" ' . escapeshellarg($path)));
-	if ($row['mtime'] < $mtime) {
+	if ($row['mtime'] < $stat['mtime']) {
 		if ($DEBUG) {
 			echo 'Updating mtime for: ' . $file . "\n";
 		}
@@ -230,14 +237,12 @@ foreach ($FILES as $file) {
 	}
 
 	# Check the file size
-	$size = trim(shell_exec('stat -c "%s" ' . escapeshellarg($path)));
-	if ($row['size'] != $size) {
+	if ($row['size'] != $stat['size']) {
 		if ($DEBUG) {
 			echo 'Updating size for: ' . $file . "\n";
 		}
-		$set_size->execute(array(':base' => $BASE_LOCAL, ':path' => $file, ':size' => $size));
+		$set_size->execute(array(':base' => $BASE_LOCAL, ':path' => $file, ':size' => $stat['size']));
 	}
-	unset($size);
 
 	# Update hashes as needed
 	if ($TYPE != 'folder') {
@@ -247,11 +252,12 @@ foreach ($FILES as $file) {
 			if ($DEBUG) {
 				echo 'Adding hash: ' . $path . "\n";
 			}
-			$hash = trim(shell_exec('md5sum ' . escapeshellarg($path) . ' | cut -d " " -f 1'));
+			$hash = trim(shell_exec('md5sum ' . escapeshellarg($path) . ' | cut -d " " -f 1 2>/dev/null'));
 			if (strlen($hash) == 32) {
 				$set_hash->execute(array(':base' => $BASE_LOCAL, ':path' => $file, ':hash' => $hash));
 			} else {
-				die('Invalid hash (' . $hash . ') for file: ' . $path . "\n");
+				echo 'Unable to hash: ' . $path . "\n";
+				continue;
 			}
 			unset($hash);
 		}

+ 5 - 1
upload.php

@@ -92,7 +92,11 @@ while ($row = $files->fetch()) {
 		echo 'Invalid file: ' . $file . "\n";
 		continue;
 	}
-	$stat = stat($file);
+	$stat = @stat($file);
+	if ($stat === false) {
+		echo 'Unable to stat: ' . $file . "\n";
+		continue;
+	}
 
 	# Upload the file
 	if ($DEBUG) {