diff --git a/GCDWebDAVServer/GCDWebDAVServer.m b/GCDWebDAVServer/GCDWebDAVServer.m
index 54e9f3c..1df6245 100644
--- a/GCDWebDAVServer/GCDWebDAVServer.m
+++ b/GCDWebDAVServer/GCDWebDAVServer.m
@@ -546,7 +546,7 @@ static inline xmlNodePtr _XMLChildWithName(xmlNodePtr child, const xmlChar* name
NSArray* items = nil;
if (isDirectory) {
NSError* error = nil;
- items = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:absolutePath error:&error];
+ items = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:absolutePath error:&error] sortedArrayUsingSelector:@selector(localizedStandardCompare:)];
if (items == nil) {
return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed listing directory \"%@\"", relativePath];
}
diff --git a/GCDWebServer/Core/GCDWebServer.m b/GCDWebServer/Core/GCDWebServer.m
index 7d4bf21..cc9b517 100644
--- a/GCDWebServer/Core/GCDWebServer.m
+++ b/GCDWebServer/Core/GCDWebServer.m
@@ -981,29 +981,29 @@ static inline NSString* _EncodeBase64(NSString* string) {
}
- (GCDWebServerResponse*)_responseWithContentsOfDirectory:(NSString*)path {
- NSDirectoryEnumerator* enumerator = [[NSFileManager defaultManager] enumeratorAtPath:path];
- if (enumerator == nil) {
+ NSArray* contents = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL] sortedArrayUsingSelector:@selector(localizedStandardCompare:)];
+ if (contents == nil) {
return nil;
}
NSMutableString* html = [NSMutableString string];
[html appendString:@"\n"];
[html appendString:@"
\n"];
[html appendString:@"\n"];
- for (NSString* file in enumerator) {
- if (![file hasPrefix:@"."]) {
- NSString* type = [[enumerator fileAttributes] objectForKey:NSFileType];
+ for (NSString* entry in contents) {
+ if (![entry hasPrefix:@"."]) {
+ NSString* type = [[[NSFileManager defaultManager] attributesOfItemAtPath:[path stringByAppendingPathComponent:entry] error:NULL] objectForKey:NSFileType];
+ GWS_DCHECK(type);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- NSString* escapedFile = [file stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+ NSString* escapedFile = [entry stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
#pragma clang diagnostic pop
GWS_DCHECK(escapedFile);
if ([type isEqualToString:NSFileTypeRegular]) {
- [html appendFormat:@"- %@
\n", escapedFile, file];
+ [html appendFormat:@"- %@
\n", escapedFile, entry];
} else if ([type isEqualToString:NSFileTypeDirectory]) {
- [html appendFormat:@"- %@/
\n", escapedFile, file];
+ [html appendFormat:@"- %@/
\n", escapedFile, entry];
}
}
- [enumerator skipDescendents];
}
[html appendString:@"
\n"];
[html appendString:@"\n"];
@@ -1176,7 +1176,7 @@ static void _LogResult(NSString* format, ...) {
_ExecuteMainThreadRunLoopSources();
result = 0;
- NSArray* files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];
+ NSArray* files = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL] sortedArrayUsingSelector:@selector(localizedStandardCompare:)];
for (NSString* requestFile in files) {
if (![requestFile hasSuffix:@".request"]) {
continue;
diff --git a/GCDWebUploader/GCDWebUploader.m b/GCDWebUploader/GCDWebUploader.m
index 6e9ed98..2ed00ed 100644
--- a/GCDWebUploader/GCDWebUploader.m
+++ b/GCDWebUploader/GCDWebUploader.m
@@ -239,7 +239,7 @@ NS_ASSUME_NONNULL_END
}
NSError* error = nil;
- NSArray* contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:absolutePath error:&error];
+ NSArray* contents = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:absolutePath error:&error] sortedArrayUsingSelector:@selector(localizedStandardCompare:)];
if (contents == nil) {
return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed listing directory \"%@\"", relativePath];
}