mirror of
https://github.com/swisspol/GCDWebServer.git
synced 2026-04-24 00:00:04 +08:00
Renamed "filePath" to "temporaryPath"
This commit is contained in:
@@ -28,5 +28,5 @@
|
||||
#import "GCDWebServerRequest.h"
|
||||
|
||||
@interface GCDWebServerFileRequest : GCDWebServerRequest
|
||||
@property(nonatomic, readonly) NSString* filePath;
|
||||
@property(nonatomic, readonly) NSString* temporaryPath;
|
||||
@end
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
@interface GCDWebServerFileRequest () {
|
||||
@private
|
||||
NSString* _filePath;
|
||||
NSString* _temporaryPath;
|
||||
int _file;
|
||||
}
|
||||
@end
|
||||
@@ -40,24 +40,24 @@ static inline NSError* _MakePosixError(int code) {
|
||||
|
||||
@implementation GCDWebServerFileRequest
|
||||
|
||||
@synthesize filePath=_filePath;
|
||||
@synthesize temporaryPath=_temporaryPath;
|
||||
|
||||
- (instancetype)initWithMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers path:(NSString*)path query:(NSDictionary*)query {
|
||||
if ((self = [super initWithMethod:method url:url headers:headers path:path query:query])) {
|
||||
_filePath = ARC_RETAIN([NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]);
|
||||
_temporaryPath = ARC_RETAIN([NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
unlink([_filePath fileSystemRepresentation]);
|
||||
ARC_RELEASE(_filePath);
|
||||
unlink([_temporaryPath fileSystemRepresentation]);
|
||||
ARC_RELEASE(_temporaryPath);
|
||||
|
||||
ARC_DEALLOC(super);
|
||||
}
|
||||
|
||||
- (BOOL)open:(NSError**)error {
|
||||
_file = open([_filePath fileSystemRepresentation], O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
_file = open([_temporaryPath fileSystemRepresentation], O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
if (_file <= 0) {
|
||||
*error = _MakePosixError(errno);
|
||||
return NO;
|
||||
@@ -81,4 +81,10 @@ static inline NSError* _MakePosixError(int code) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSString*)description {
|
||||
NSMutableString* description = [NSMutableString stringWithString:[super description]];
|
||||
[description appendFormat:@"\n\n{%@}", _temporaryPath];
|
||||
return description;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -125,13 +125,13 @@ static inline BOOL _IsMacFinder(GCDWebServerRequest* request) {
|
||||
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"Uploaded file name \"%@\" is not allowed", fileName];
|
||||
}
|
||||
|
||||
if (![self shouldUploadFileAtPath:absolutePath withTemporaryFile:request.filePath]) {
|
||||
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"Uploading file to \"%@\" is not allowed", relativePath];
|
||||
if (![self shouldUploadFileAtPath:absolutePath withTemporaryFile:request.temporaryPath]) {
|
||||
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"Uploading file to \"%@\" is not permitted", relativePath];
|
||||
}
|
||||
|
||||
[[NSFileManager defaultManager] removeItemAtPath:absolutePath error:NULL];
|
||||
NSError* error = nil;
|
||||
if (![[NSFileManager defaultManager] moveItemAtPath:request.filePath toPath:absolutePath error:&error]) {
|
||||
if (![[NSFileManager defaultManager] moveItemAtPath:request.temporaryPath toPath:absolutePath error:&error]) {
|
||||
return [GCDWebServerErrorResponse responseWithServerError:kGCDWebServerHTTPStatusCode_InternalServerError underlyingError:error message:@"Failed moving uploaded file to \"%@\"", relativePath];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user