Skip to content

Commit 478a6a0

Browse files
author
Marius Cramer
committed
Merge branch 'master' into 'master'
Master
2 parents 11ca0c5 + 852a25f commit 478a6a0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

server/lib/classes/system.inc.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,38 @@ function checkpath($path) {
913913
}
914914

915915

916+
/**
917+
* This function checks the free space for a given directory
918+
* @param path check path
919+
* @param limit min. free space in bytes
920+
* @return bool - true when the the free space is above limit ohterwise false, opt. available disk-space
921+
*/
922+
923+
function check_free_space($path, $limit = 0, &$free_space = 0) {
924+
$path = rtrim($path, '/');
925+
926+
/**
927+
* Make sure that we have only existing directories in the path.
928+
929+
* Given a file name instead of a directory, the behaviour of the disk_free_space
930+
function is unspecified and may differ between operating systems and PHP versions.
931+
*/
932+
while(!is_dir($path) && $path != '/') $path = realpath(dirname($path));
933+
934+
$free_space = disk_free_space($out);
935+
936+
if (!$free_space) {
937+
$free_space = 0;
938+
return false;
939+
}
940+
941+
if ($free_space >= $limit) {
942+
return true;
943+
} else {
944+
return false;
945+
}
946+
947+
}
916948

917949

918950

0 commit comments

Comments
 (0)