Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-23141] iOS: Fix Ti.Filesystem.File.remoteBackup #7910

Merged
merged 3 commits into from
Apr 5, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions iphone/Classes/TiFilesystemFileProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
@property(nonatomic,readonly) id executable;
@property(nonatomic,readonly) id hidden;

@property(nonatomic,readwrite,assign) NSNumber* remoteBackup;


@end

#endif
44 changes: 22 additions & 22 deletions iphone/Classes/TiFilesystemFileProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#define FILE_TOSTR(x) \
([x isKindOfClass:[TiFilesystemFileProxy class]]) ? [(TiFilesystemFileProxy*)x nativePath] : [TiUtils stringValue:x]

static const char* backupAttr = "com.apple.MobileBackup";

@implementation TiFilesystemFileProxy

-(id)initWithFile:(NSString*)path_
Expand Down Expand Up @@ -492,33 +490,35 @@ +(id)makeTemp:(BOOL)isDirectory

-(NSNumber*)remoteBackup
{
u_int8_t value;
const char* fullPath = [[self path] fileSystemRepresentation];

ssize_t result = getxattr(fullPath, backupAttr, &value, sizeof(value), 0, 0);
if (result == -1) {
// Doesn't matter what errno is set to; this means that we're backing up.
return [NSNumber numberWithBool:YES];
NSURL *URL = [NSURL fileURLWithPath: [self path]];
NSError *error;
NSNumber *isExcluced;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor spelling error. should be isExcluded


BOOL success = [URL getResourceValue:&isExcluced
forKey:NSURLIsExcludedFromBackupKey error:&error];
if (!success) {
// Doesn't matter what error is set to; this means that we're backing up.
return NUMBOOL(YES);
}

// A value of 0 means backup, so:
return [NSNumber numberWithBool:!value];
// A value of @FALSE means backup, so:
return NUMBOOL([isExcluced isEqualToNumber:@YES] ? NO : YES);
}

-(void)setRemoteBackup:(NSNumber *)remoteBackup
-(void)setRemoteBackup:(id)value
{
// Value of 1 means nobackup
u_int8_t value = ![TiUtils boolValue:remoteBackup def:YES];
const char* fullPath = [[self path] fileSystemRepresentation];
ENSURE_TYPE(value, NSNumber);

BOOL isExcluced = ![TiUtils boolValue:value def:YES];
NSURL *URL= [NSURL fileURLWithPath: [self path]];
NSError *error;

int result = setxattr(fullPath, backupAttr, &value, sizeof(value), 0, 0);
if (result != 0) {
// Throw an exception with the errno
char* errmsg = strerror(errno);
[self throwException:@"Error setting remote backup flag:"
subreason:[NSString stringWithUTF8String:errmsg]
BOOL success = [URL setResourceValue:NUMBOOL(isExcluced)
forKey:NSURLIsExcludedFromBackupKey error:&error];
if (!success) {
[self throwException:@"Error setting remote backup flag:"
subreason:[error localizedDescription]
location:CODELOCATION];
return;
}
}

Expand Down