X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fmain.inc;h=ee604df88e275e7e3c34b34903353066e787eab0;hb=fea32048f1b2874f75b7f15af5f2d9667163a4d8;hp=3686aebea0dfc58a58833b37e728ee936fa07c96;hpb=303eb17e9cdd9702eee9fdfcaee51e654a1da541;p=fa-stable.git diff --git a/includes/main.inc b/includes/main.inc index 3686aebe..ee604df8 100644 --- a/includes/main.inc +++ b/includes/main.inc @@ -262,4 +262,55 @@ function js_compress($sJS) return $sJS; } +/* + Check if file can be updated, restoring subdirectories + if needed. Returns 1 when no confilcts, -1 when file exists and is writable +*/ +function check_write($path) +{ + if ($path == ''//|| $path == '.' || $path == '..' + ) return 0; + + return is_writable($path) ? (is_dir($path) ? 1 : -1) + : ($path =='.' ? 0 : check_write(dirname($path))); +} + +/* + Copies set of files. When $strict is set + also removes files from the $to which + does not exists in $from directory but arelisted in $flist. +*/ +function copy_files($flist, $from, $to, $strict=false) +{ + foreach ($flist as $file) { + if (file_exists($from.'/'.$file)) + if (!copy_file($file, $from, $to)) + return false; + if ($strict && !is_file($from.'/'.$file)) // if + unlink($to.'/'.$file); + } + return true; +} + +/* + Copies file from base to target directory, restoring subdirectories + if needed. +*/ +function copy_file($file, $from, $to) +{ + + if (!is_dir(dirname($file=='.' ? $to : ($to.'/'.$file)))) { + if (!copy_file(dirname($file), null, $to)) + return false; + } + if (!$from) { + // error_log( 'dodanie katalogu '.$to.'/'.$file); + return @mkdir($file=='.' ? $to : ($to.'/'.$file)); + } + else { + // error_log( 'skopiowanie '.$to.'/'.$file); + return @copy($from.'/'.$file, $to.'/'.$file); + } +} + ?> \ No newline at end of file