Skip to content

Commit 852a25f

Browse files
author
Florian Schaal
committed
changed function check_free_space
1 parent b769cc8 commit 852a25f

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

server/lib/classes/system.inc.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -917,33 +917,28 @@ function checkpath($path) {
917917
* This function checks the free space for a given directory
918918
* @param path check path
919919
* @param limit min. free space in bytes
920-
* @return bool - true when the the free space is above limit ohterwise false
920+
* @return bool - true when the the free space is above limit ohterwise false, opt. available disk-space
921921
*/
922922

923-
function check_free_space($path, $limit = 0) {
923+
function check_free_space($path, $limit = 0, &$free_space = 0) {
924924
$path = rtrim($path, '/');
925-
$parts = explode('/', $path);
926-
$out = '';
927925

928926
/**
929927
* Make sure that we have only existing directories in the path.
930928
931929
* Given a file name instead of a directory, the behaviour of the disk_free_space
932930
function is unspecified and may differ between operating systems and PHP versions.
933931
*/
934-
for ($i = 1; $i < count($parts); $i++) {
935-
if ( !is_file($out.'/'.$parts[$i]) && is_dir($out.'/'.$parts[$i]) ) {
936-
$out .= '/'.$parts[$i];
937-
}
938-
}
939-
940-
unset($parts);
932+
while(!is_dir($path) && $path != '/') $path = realpath(dirname($path));
941933

942-
$res = disk_free_space($out);
934+
$free_space = disk_free_space($out);
943935

944-
if (!$res) return false;
936+
if (!$free_space) {
937+
$free_space = 0;
938+
return false;
939+
}
945940

946-
if ($res >= $limit) {
941+
if ($free_space >= $limit) {
947942
return true;
948943
} else {
949944
return false;

0 commit comments

Comments
 (0)