Error was code: 63 - message: File name too long #12

Closed
reallylongaddress opened this Issue Oct 9, 2011 · 2 comments

Comments

Projects
None yet
2 participants

Hi there...

Been playing with your AFCache and got the above error (My urls are pretty darn long). So here's my hack/fix...do as you wish with it:

2011-10-09 09:57:45.091 MobileIgniter[7629:207] Error: could not create file "/Users/dominic/Library/Application Support/iPhone Simulator/4.0.2/Applications/99347D6D-885F-4E87-9D6B-7F553CC96062/Library/Caches/com.mobileigniter.proofofconcept.tropicana/localhost:8888/modules/index.php/listDetail/?signed_request=8mIgkXSbpKrxnKdIM1moOzTN66oFqSukvgwkS_HltWs.eyJ0aXRsZSI6IlRyb3BpY2FuYSBEZWFscyIsIm1vZHVsZV9rZXkiOiJsaXN0X2RldGFpbF9tb2R1bGVfa2V5IiwibW9kdWxlX2luc3RhbmNlX2tleSI6IndrbXozMjh2MGtubGFydmM4ZTM5ZzVkbGZtcjJqYzI2In0&system_name=iPhone%20OS&system_version=4.0.2"

2011-10-09 09:57:45.098 MobileIgniter[7629:207] Error was code: 63 - message: File name too long

----SO I shortened the url part of the filename via MD5-----

  • (NSString *)filePathForURL: (NSURL *) url {

    NSLog(@"dataPath: %@", dataPath);
    NSLog(@"filenameForUrl: %@", [self filenameForURL: url]);

    //dbd let's md5 the url else we get an error (Error was code: 63 - message: File name too long)
    NSString *hashedFilename = [StringUtils returnMD5Hash:[self filenameForURL: url]];

    NSLog(@"hashedFilename: %@", hashedFilename);

    NSLog(@"before/after %i/%i", [[self filenameForURL: url] length], [hashedFilename length]);

    return [dataPath stringByAppendingPathComponent:hashedFilename];
    }

----WHERE MD5 generated via---
//generate md5 hash from string

  • (NSString ) returnMD5Hash:(NSString)concat {
    const char *concat_str = [concat UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    CC_MD5(concat_str, strlen(concat_str), result);
    NSMutableString *hash = [NSMutableString string];
    for (int i = 0; i < 16; i++)
    [hash appendFormat:@"%02X", result[i]];
    return [hash lowercaseString];

}

Best,
Dominic

After a bit more coding...i've moved the md5 function so it's accessed via all filepath generation:

  • (NSString )filenameForURLString: (NSString *) URLString {
    #ifdef AFCACHE_MAINTAINER_WARNINGS
    #warning TODO cleanup
    #endif
    if ([URLString hasPrefix:@"data:"]) return nil;
    NSString *filepath = [URLString stringByRegex:@".
    ://" substitution:@""];
    NSString filepath1 = [filepath stringByRegex:@":[0-9]?/" substitution:@""];
    NSString filepath2 = [filepath1 stringByRegex:@"#." substitution:@""];
    NSString filepath3 = [filepath2 stringByRegex:@"?." substitution:@""];
    NSString filepath4 = [filepath3 stringByRegex:@"//" substitution:@"/"];
    NSLog(@"fielnameForURLString: %@", [StringUtils returnMD5Hash:filepath4]);
    return [StringUtils returnMD5Hash:filepath4];
    // return filepath4;
    }

//DBD modified this to shorten the filename, else we get a 'file name too long' error

  • (NSString *)filePathForURL: (NSURL *) url {

    NSLog(@"filePathForURL: %@", [dataPath stringByAppendingPathComponent:[self filenameForURL: url]]);
    return [dataPath stringByAppendingPathComponent:[self filenameForURL: url]];
    }

Owner

artifacts commented Sep 26, 2014

Filenames are hashes now, so this won't happen anymore.

@artifacts artifacts closed this Sep 26, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment