Revision: 4132
http://skim-app.svn.sourceforge.net/skim-app/?rev=4132&view=rev
Author: hofman
Date: 2008-07-05 06:17:04 -0700 (Sat, 05 Jul 2008)
Log Message:
-----------
Log some more error info when subattributes fail. Drop attribute names for
fragments when getting all attributes.
Modified Paths:
--------------
trunk/SkimNotes/SKNExtendedAttributeManager.h
trunk/SkimNotes/SKNExtendedAttributeManager.m
Modified: trunk/SkimNotes/SKNExtendedAttributeManager.h
===================================================================
--- trunk/SkimNotes/SKNExtendedAttributeManager.h 2008-07-04 16:34:52 UTC
(rev 4131)
+++ trunk/SkimNotes/SKNExtendedAttributeManager.h 2008-07-05 13:17:04 UTC
(rev 4132)
@@ -99,7 +99,7 @@
@method extendedAttributeNamesAtPath:traverseLink:
@abstract Return a list of extended attributes for the given file.
@discussion Calls <code>listxattr(2)</code> to determine all of the
extended attributes, and returns them as
- an array of <code>NSString</code> objects. Returns
<code>nil</code> if an error occurs.
+ an array of <code>NSString</code> objects. Returns
<code>nil</code> if an error occurs. Does not return attribute names for
fragments.
@param path Path to the object in the file system.
@param follow Follow symlinks (<code>listxattr(2)</code> does this by
default, so typically you should pass <code>YES</code>).
@param error Error object describing the error if <code>nil</code>
was returned.
Modified: trunk/SkimNotes/SKNExtendedAttributeManager.m
===================================================================
--- trunk/SkimNotes/SKNExtendedAttributeManager.m 2008-07-04 16:34:52 UTC
(rev 4131)
+++ trunk/SkimNotes/SKNExtendedAttributeManager.m 2008-07-05 13:17:04 UTC
(rev 4132)
@@ -44,8 +44,10 @@
@interface SKNExtendedAttributeManager (SKNPrivate)
// private methods to (un)compress data
-- (NSData *)bzip2Data:(NSData *)data;
-- (NSData *)bunzip2Data:(NSData *)data;
+- (NSData *)bzipData:(NSData *)data;
+- (NSData *)bunzipData:(NSData *)data;
+- (BOOL)isBzipData:(NSData *)data;
+- (BOOL)isPlistData:(NSData *)data;
// private method to print error messages
- (NSError *)xattrError:(int)err forPath:(NSString *)path;
@end
@@ -152,7 +154,8 @@
for(idx = 0; idx < bufSize; idx++){
if(namebuf[idx] == '\0'){
attribute = [[NSString alloc] initWithBytes:&namebuf[start]
length:(idx - start) encoding:NSUTF8StringEncoding];
- if(attribute) [attrs addObject:attribute];
+ // ignore fragments
+ if(attribute && (namePrefix == nil || [attribute
hasPrefix:namePrefix] == NO)) [attrs addObject:attribute];
[attribute release];
attribute = nil;
start = idx + 1;
@@ -226,17 +229,9 @@
NSPropertyListFormat format;
NSString *errorString;
-
- // the plist parser logs annoying messages when failing to parse non-plist
data, so sniff the header (this is correct for the binary plist that we use for
split data)
- static NSData *plistHeaderData = nil;
- if (nil == plistHeaderData) {
- char *h = "bplist00";
- plistHeaderData = [[NSData alloc] initWithBytes:h length:strlen(h)];
- }
-
id plist = nil;
- if (namePrefix && [attribute length] >= [plistHeaderData length] &&
[plistHeaderData isEqual:[attribute subdataWithRange:NSMakeRange(0,
[plistHeaderData length])]])
+ if (namePrefix && [self isPlistData:attribute])
plist = [NSPropertyListSerialization propertyListFromData:attribute
mutabilityOption:NSPropertyListImmutable format:&format
errorDescription:&errorString];
// even if it's a plist, it may not be a dictionary or have the key we're
looking for
@@ -251,14 +246,15 @@
BOOL success = (nil != uniqueValue && numberOfFragments > 0);
if (success == NO)
- NSLog(@"failed to read unique key %@ from property list.",
uniqueKey);
+ NSLog(@"failed to read unique key %@ for %i fragments from
property list.", uniqueKey, numberOfFragments);
// reassemble the original data object
for (i = 0; success && i < numberOfFragments; i++) {
+ NSError *tmpError = nil;
name = [NSString stringWithFormat:@"[EMAIL PROTECTED]",
uniqueValue, i];
- subdata = [self extendedAttributeNamed:name atPath:path
traverseLink:follow error:error];
+ subdata = [self extendedAttributeNamed:name atPath:path
traverseLink:follow error:&tmpError];
if (nil == subdata) {
- NSLog(@"failed to find subattribute %@ of attribute named %@",
name, attr);
+ NSLog(@"failed to find subattribute %@ of %i for attribute
named [EMAIL PROTECTED] %@", name, numberOfFragments, attr, [tmpError
localizedDescription]);
success = NO;
} else {
[buffer appendData:subdata];
@@ -266,7 +262,7 @@
}
[attribute release];
- attribute = success ? [[self bunzip2Data:buffer] retain] : nil;
+ attribute = success ? [[self bunzipData:buffer] retain] : nil;
if (success == NO && NULL != error) *error = [NSError
errorWithDomain:SKNErrorDomain code:0 userInfo:[NSDictionary
dictionaryWithObjectsAndKeys:path, NSFilePathErrorKey,
SKNLocalizedString(@"Failed to reassemble attribute value.", @"Error
description"), NSLocalizedDescriptionKey, nil]];
}
@@ -282,15 +278,9 @@
if (error) *error = anError;
} else {
// decompress the data if necessary, we may have compressed when
setting
- static NSData *bzipHeaderData = nil;
- if (nil == bzipHeaderData) {
- char *h = "BZh";
- bzipHeaderData = [[NSData alloc] initWithBytes:h length:strlen(h)];
- }
+ if ([self isBzipData:data])
+ data = [self bunzipData:data];
- if ([data length] >= [bzipHeaderData length] && [bzipHeaderData
isEqual:[data subdataWithRange:NSMakeRange(0, [bzipHeaderData length])]])
- data = [self bunzip2Data:data];
-
NSString *errorString;
plist = [NSPropertyListSerialization propertyListFromData:data
mutabilityOption:NSPropertyListImmutable
@@ -326,7 +316,7 @@
if ((options & kSKNXattrNoSplitData) == 0 && namePrefix && [value length]
> MAX_XATTR_LENGTH) {
// compress to save space, and so we don't identify this as a plist
when reading it (in case it really is plist data)
- value = [self bzip2Data:value];
+ value = [self bzipData:value];
// this will be a unique identifier for the set of keys we're about to
write (appending a counter to the UUID)
NSString *uniqueValue = [namePrefix
stringByAppendingString:UNIQUE_VALUE];
@@ -385,7 +375,7 @@
} else {
// if we don't split and the data is too long, compress the data using
bzip to save space
if (((options & kSKNXattrNoSplitData) != 0 || namePrefix == nil) &&
[data length] > MAX_XATTR_LENGTH)
- data = [self bzip2Data:data];
+ data = [self bzipData:data];
success = [self setExtendedAttributeNamed:attr toValue:data
atPath:path options:options error:error];
}
@@ -422,17 +412,9 @@
NSPropertyListFormat format;
NSString *errorString;
-
- // the plist parser logs annoying messages when failing to parse
non-plist data, so sniff the header (this is correct for the binary plist that
we use for split data)
- static NSData *plistHeaderData = nil;
- if (nil == plistHeaderData) {
- char *h = "bplist00";
- plistHeaderData = [[NSData alloc] initWithBytes:h
length:strlen(h)];
- }
-
id plist = nil;
- if (namePrefix && [attribute length] >= [plistHeaderData length]
&& [plistHeaderData isEqual:[attribute subdataWithRange:NSMakeRange(0,
[plistHeaderData length])]])
+ if (namePrefix && [self isPlistData:attribute])
plist = [NSPropertyListSerialization
propertyListFromData:attribute mutabilityOption:NSPropertyListImmutable
format:&format errorDescription:&errorString];
// even if it's a plist, it may not be a dictionary or have the
key we're looking for
@@ -557,7 +539,7 @@
// implementation modified after
http://www.cocoadev.com/index.pl?NSDataPlusBzip (removed exceptions)
//
-- (NSData *)bzip2Data:(NSData *)data;
+- (NSData *)bzipData:(NSData *)data;
{
int compression = 5;
int bzret, buffer_size = 1000000;
@@ -591,7 +573,7 @@
return compressed;
}
-- (NSData *)bunzip2Data:(NSData *)data;
+- (NSData *)bunzipData:(NSData *)data;
{
int bzret;
bz_stream stream = { 0 };
@@ -625,4 +607,29 @@
return decompressed;
}
+- (BOOL)isBzipData:(NSData *)data;
+{
+ static NSData *bzipHeaderData = nil;
+ static unsigned int bzipHeaderDataLength;
+ if (nil == bzipHeaderData) {
+ char *h = "BZh";
+ bzipHeaderData = [[NSData alloc] initWithBytes:h length:strlen(h)];
+ }
+
+ return [data length] >= bzipHeaderDataLength && [bzipHeaderData
isEqual:[data subdataWithRange:NSMakeRange(0, bzipHeaderDataLength)]];
+}
+
+- (BOOL)isPlistData:(NSData *)data;
+{
+ static NSData *plistHeaderData = nil;
+ static unsigned int plistHeaderDataLength;
+ if (nil == plistHeaderData) {
+ char *h = "bplist00";
+ plistHeaderData = [[NSData alloc] initWithBytes:h length:strlen(h)];
+ plistHeaderDataLength = [plistHeaderData length];
+ }
+
+ return [data length] >= plistHeaderDataLength && [plistHeaderData
isEqual:[data subdataWithRange:NSMakeRange(0, plistHeaderDataLength)]];
+}
+
@end
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit