@@ -148,13 +148,13 @@ function move(&$options) {
148
148
return true ;
149
149
}
150
150
151
- // FIXME Handle depth
152
151
// FIXME Use file_exists
153
152
function propfind ($ options , &$ files ) {
154
153
$ files = array ();
155
- $ paths = array ();
156
- $ path = $ options ['path ' ];
157
- while (isset ($ path )) {
154
+ $ paths = array (array ($ options ['path ' ], 0 ));
155
+ while (!empty ($ paths )) {
156
+ list ($ path , $ depth ) = array_pop ($ paths );
157
+
158
158
$ file = array ();
159
159
$ file ['path ' ] = $ path ;
160
160
@@ -168,26 +168,28 @@ function propfind($options, &$files) {
168
168
if (is_dir ($ absolutePath )) {
169
169
$ file ['props ' ][] = $ this ->mkprop ('resourcetype ' , 'collection ' );
170
170
171
- $ handle = opendir ($ absolutePath );
172
- if (!$ handle ) {
173
- return ;
174
- }
171
+ if ($ depth < $ options ['depth ' ]) {
172
+ $ handle = opendir ($ absolutePath );
173
+ if (!$ handle ) {
174
+ return ;
175
+ }
175
176
176
- while (($ pathComponent = readdir ($ handle )) !== false ) {
177
- if ($ pathComponent != '. ' && $ pathComponent != '.. ' ) {
178
- $ paths [] = $ path != '' ? "$ path/ $ pathComponent " :
179
- $ pathComponent ;
177
+ while (($ pathComponent = readdir ($ handle )) !== false ) {
178
+ if ($ pathComponent != '. ' && $ pathComponent != '.. ' ) {
179
+ $ paths [] = array ($ path != '' ?
180
+ "$ path/ $ pathComponent " : $ pathComponent ,
181
+ $ depth + 1 );
182
+ }
180
183
}
184
+ closedir ($ handle );
181
185
}
182
- closedir ($ handle );
183
186
} else {
184
187
$ file ['props ' ][] = $ this ->mkprop ('getcontentlength ' ,
185
188
$ stat ['size ' ]);
186
189
$ file ['props ' ][] = $ this ->mkprop ('resourcetype ' , null );
187
190
}
188
191
189
192
$ files [] = $ file ;
190
- $ path = array_pop ($ paths );
191
193
}
192
194
193
195
return true ;
@@ -211,9 +213,10 @@ function put(&$options) {
211
213
212
214
function report ($ options , &$ files ) {
213
215
$ files = array ();
214
- $ paths = array ();
215
- $ path = $ options ['path ' ];
216
- while (isset ($ path )) {
216
+ $ paths = array (array ($ options ['path ' ], 0 ));
217
+ while (!empty ($ paths )) {
218
+ list ($ path , $ depth ) = array_pop ($ paths );
219
+
217
220
$ file = array ();
218
221
$ file ['path ' ] = $ path ;
219
222
@@ -227,26 +230,28 @@ function report($options, &$files) {
227
230
if (is_dir ($ absolutePath )) {
228
231
$ file ['props ' ][] = $ this ->mkprop ('resourcetype ' , 'collection ' );
229
232
230
- $ handle = opendir ($ absolutePath );
231
- if (!$ handle ) {
232
- return ;
233
- }
233
+ if ($ depth < $ options ['depth ' ]) {
234
+ $ handle = opendir ($ absolutePath );
235
+ if (!$ handle ) {
236
+ return ;
237
+ }
234
238
235
- while (($ pathComponent = readdir ($ handle )) !== false ) {
236
- if ($ pathComponent != '. ' && $ pathComponent != '.. ' ) {
237
- $ paths [] = $ path != '' ? "$ path/ $ pathComponent " :
238
- $ pathComponent ;
239
+ while (($ pathComponent = readdir ($ handle )) !== false ) {
240
+ if ($ pathComponent != '. ' && $ pathComponent != '.. ' ) {
241
+ $ paths [] = array ($ path != '' ?
242
+ "$ path/ $ pathComponent " : $ pathComponent ,
243
+ $ depth + 1 );
244
+ }
239
245
}
246
+ closedir ($ handle );
240
247
}
241
- closedir ($ handle );
242
248
} else {
243
249
$ file ['props ' ][] = $ this ->mkprop ('getcontentlength ' ,
244
250
$ stat ['size ' ]);
245
251
$ file ['props ' ][] = $ this ->mkprop ('resourcetype ' , null );
246
252
}
247
253
248
254
$ files [] = $ file ;
249
- $ path = array_pop ($ paths );
250
255
}
251
256
252
257
return true ;
0 commit comments