| | 122 | /** |
|---|
| | 123 | * Sort array of filenames to alphabetical tree order |
|---|
| | 124 | */ |
|---|
| | 125 | function by_tree($a_part, $b_part) |
|---|
| | 126 | { |
|---|
| | 127 | global $dump_path; |
|---|
| | 128 | $a_path = $dump_path . $a_part; |
|---|
| | 129 | $b_path = $dump_path . $b_part; |
|---|
| | 130 | $a_components = explode('/', $a_part); |
|---|
| | 131 | $b_components = explode('/', $b_part); |
|---|
| | 132 | $a_score = count($a_components); |
|---|
| | 133 | $b_score = count($b_components); |
|---|
| | 134 | if (is_dir($a_path)) |
|---|
| | 135 | { |
|---|
| | 136 | --$a_score; |
|---|
| | 137 | } |
|---|
| | 138 | if (is_dir($b_path)) |
|---|
| | 139 | { |
|---|
| | 140 | --$b_score; |
|---|
| | 141 | } |
|---|
| | 142 | if ($a_score === $b_score) |
|---|
| | 143 | { |
|---|
| | 144 | // Equal scores, sort by strnatcmp |
|---|
| | 145 | return strnatcmp($a_part, $b_part); |
|---|
| | 146 | } |
|---|
| | 147 | // Standard gt/lt response |
|---|
| | 148 | if ($a_score > $b_score) |
|---|
| | 149 | { |
|---|
| | 150 | return 1; |
|---|
| | 151 | } |
|---|
| | 152 | if ($a_score < $b_score) |
|---|
| | 153 | { |
|---|
| | 154 | return -1; |
|---|
| | 155 | } |
|---|
| | 156 | } |
|---|
| | 157 | |
|---|
| | 158 | usort($remove_files, 'by_tree'); |
|---|
| | 159 | $remove_files = array_reverse($remove_files); |
|---|
| | 160 | /* |
|---|
| | 161 | echo "DEBUG: remove_files (ofter sort)\n"; |
|---|
| | 162 | print_r($remove_files); |
|---|
| | 163 | */ |
|---|