@@ -9,6 +9,29 @@ function jsend(array $data, int $code = 200): void {
99 exit ;
1010}
1111
12+ // -------------------- FILE EXCLUDES --------------------
13+ const FILE_EXCLUDES = [
14+ '.DS_Store ' ,
15+ '__MACOSX ' ,
16+ 'Thumbs.db ' ,
17+ ];
18+
19+ const FILE_EXCLUDE_PREFIXES = [
20+ '._ ' , // AppleDouble files
21+ ];
22+
23+ function is_excluded_file (string $ name ): bool {
24+ if (in_array ($ name , FILE_EXCLUDES , true )) {
25+ return true ;
26+ }
27+ foreach (FILE_EXCLUDE_PREFIXES as $ prefix ) {
28+ if (str_starts_with ($ name , $ prefix )) {
29+ return true ;
30+ }
31+ }
32+ return false ;
33+ }
34+
1235function norm_rel (string $ rel ): string {
1336 $ rel = str_replace ("\0" , '' , $ rel );
1437 $ rel = str_replace ('\\' , '/ ' , $ rel );
@@ -67,6 +90,7 @@ function list_dir(string $rel): array {
6790 if (!$ dh ) jsend (['ok ' =>false ,'error ' =>'Cannot open dir ' ], 500 );
6891 while (($ name = readdir ($ dh )) !== false ) {
6992 if ($ name === '. ' || $ name === '.. ' ) continue ;
93+ if (is_excluded_file ($ name )) continue ;
7094 $ p = $ abs . DIRECTORY_SEPARATOR . $ name ;
7195 $ isDir = is_dir ($ p );
7296 $ stat = @stat ($ p );
@@ -95,6 +119,7 @@ function build_tree(string $rel = ''): array {
95119 if (!$ dh ) return [];
96120 while (($ name = readdir ($ dh )) !== false ) {
97121 if ($ name === '. ' || $ name === '.. ' ) continue ;
122+ if (is_excluded_file ($ name )) continue ;
98123 $ p = $ abs . DIRECTORY_SEPARATOR . $ name ;
99124 if (!is_dir ($ p )) continue ;
100125 $ childRel = norm_rel (($ rel === '' ? '' : $ rel .'/ ' ) . $ name );
@@ -117,6 +142,7 @@ function has_dir_children(string $rel): bool {
117142 if (!$ dh ) return false ;
118143 while (($ name = readdir ($ dh )) !== false ) {
119144 if ($ name === '. ' || $ name === '.. ' ) continue ;
145+ if (is_excluded_file ($ name )) continue ;
120146 if (is_dir ($ abs . DIRECTORY_SEPARATOR . $ name )) { closedir ($ dh ); return true ; }
121147 }
122148 closedir ($ dh );
@@ -150,6 +176,7 @@ function rrcopy(string $src, string $dst): void {
150176 $ it = new DirectoryIterator ($ src );
151177 foreach ($ it as $ f ) {
152178 if ($ f ->isDot ()) continue ;
179+ if (is_excluded_file ($ f ->getFilename ())) continue ;
153180 rrcopy ($ src . DIRECTORY_SEPARATOR . $ f ->getFilename (), $ dst . DIRECTORY_SEPARATOR . $ f ->getFilename ());
154181 }
155182 } else {
0 commit comments