Skip to content

Commit

Permalink
Removing Mount All and cleaning up helper
Browse files Browse the repository at this point in the history
Remove the Mount All menu entry, since it is no longer useful. Mounting
should be done at a dataset level if needed, and most of the time done
automatically.
Also remove vestiges of unmount all / mount all from the helper and add
some additional error checking in its place.
  • Loading branch information
cbreak-black committed Oct 14, 2019
1 parent a2d8e7b commit ecd5faf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 76 deletions.
95 changes: 40 additions & 55 deletions ZetaAuthorizationHelper/ZetaAuthorizationHelper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ - (void)exportPools:(NSDictionary *)exportData authorization:(NSData *)authData
bool force = false;
if (id o = [exportData objectForKey:@"force"])
force = [o boolValue];
if (!poolName)
{
reply([NSError errorWithDomain:@"ZFSArgError" code:-1 userInfo:@{NSLocalizedDescriptionKey: @"Missing Arguments"}]);
return;
}
try
{
auto pool = _zfs.pool(std::string(poolName.UTF8String));
Expand Down Expand Up @@ -296,34 +301,24 @@ - (void)mountFilesystems:(NSDictionary *)mountData authorization:(NSData *)authD
bool recursive = false;
if (id o = [mountData objectForKey:@"recursive"])
recursive = [o boolValue];
if (!fsName)
{
reply([NSError errorWithDomain:@"ZFSArgError" code:-1 userInfo:@{NSLocalizedDescriptionKey: @"Missing Arguments"}]);
return;
}
try
{
std::vector<std::string> failures;
if (fsName)
{
auto fs = _zfs.filesystem([fsName UTF8String]);
if (!fs.mount())
failures.emplace_back(_zfs.lastError());
if (recursive)
{
fs.iterAllFileSystems([self,&failures](zfs::ZFileSystem fs)
{
if (!fs.mount())
failures.emplace_back(_zfs.lastError());
return 0;
});
}
}
else
auto fs = _zfs.filesystem([fsName UTF8String]);
if (!fs.mount())
failures.emplace_back(_zfs.lastError());
if (recursive)
{
_zfs.iterPools([self,&failures](zfs::ZPool pool)
fs.iterAllFileSystems([self,&failures](zfs::ZFileSystem fs)
{
pool.iterAllFileSystems([self,&failures](zfs::ZFileSystem fs)
{
if (!fs.mount())
failures.emplace_back(_zfs.lastError());
return 0;
});
if (!fs.mount())
failures.emplace_back(_zfs.lastError());
return 0;
});
}
if (failures.empty())
Expand Down Expand Up @@ -363,45 +358,35 @@ - (void)unmountFilesystems:(NSDictionary *)mountData authorization:(NSData *)aut
bool recursive = false;
if (id o = [mountData objectForKey:@"recursive"])
recursive = [o boolValue];
if (!fsName)
{
reply([NSError errorWithDomain:@"ZFSArgError" code:-1 userInfo:@{NSLocalizedDescriptionKey: @"Missing Arguments"}]);
return;
}
try
{
std::vector<std::string> failures;
if (fsName)
auto fs = _zfs.filesystem([fsName UTF8String]);
if (recursive)
{
auto fs = _zfs.filesystem([fsName UTF8String]);
if (recursive)
auto unmountSnap = [self,&failures,force](zfs::ZFileSystem snap)
{
auto unmountSnap = [self,&failures,force](zfs::ZFileSystem snap)
{
if (!snap.unmount(force))
failures.emplace_back(_zfs.lastError());
return 0;
};
auto unmountFS = [self,&failures,force,&unmountSnap](zfs::ZFileSystem fs)
{
fs.iterSnapshots(unmountSnap);
if (!fs.unmount(force))
failures.emplace_back(_zfs.lastError());
return 0;
};
fs.iterAllFileSystemsReverse(unmountFS);
fs.iterSnapshots(unmountSnap);
}
if (!fs.unmount(force))
failures.emplace_back(_zfs.lastError());
}
else
{
_zfs.iterPools([self,&failures,force](zfs::ZPool pool)
if (!snap.unmount(force))
failures.emplace_back(_zfs.lastError());
return 0;
};
auto unmountFS = [self,&failures,force,&unmountSnap](zfs::ZFileSystem fs)
{
pool.iterAllFileSystemsReverse([self,&failures,force](zfs::ZFileSystem fs)
{
if (!fs.unmount(force))
failures.emplace_back(_zfs.lastError());
return 0;
});
});
fs.iterSnapshots(unmountSnap);
if (!fs.unmount(force))
failures.emplace_back(_zfs.lastError());
return 0;
};
fs.iterAllFileSystemsReverse(unmountFS);
fs.iterSnapshots(unmountSnap);
}
if (!fs.unmount(force))
failures.emplace_back(_zfs.lastError());
if (failures.empty())
{
reply(nullptr);
Expand Down
6 changes: 0 additions & 6 deletions ZetaWatch/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@
</connections>
</menu>
</menuItem>
<menuItem title="Mount all Filesystems" id="Gk5-sm-R9o">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="mountAllFilesystems:" target="8rf-zp-5r9" id="bPj-lW-Dmo"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="Ttd-8u-p8d"/>
<menuItem title="Settings" id="abZ-nP-vC5">
<modifierMask key="keyEquivalentModifierMask"/>
Expand Down
1 change: 0 additions & 1 deletion ZetaWatch/ZetaMainMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ enum ZetaMenuTags

- (IBAction)exportPool:(id)sender;
- (IBAction)exportPoolForce:(id)sender;
- (IBAction)mountAllFilesystems:(id)sender;
- (IBAction)mountFilesystem:(id)sender;
- (IBAction)mountFilesystemRecursive:(id)sender;
- (IBAction)unmountFilesystem:(id)sender;
Expand Down
14 changes: 0 additions & 14 deletions ZetaWatch/ZetaMainMenu.mm
Original file line number Diff line number Diff line change
Expand Up @@ -604,20 +604,6 @@ - (IBAction)exportPoolForce:(id)sender
}];
}

- (IBAction)mountAllFilesystems:(id)sender
{
[_authorization mountFilesystems:@{} withReply:^(NSError * error)
{
if (!error)
{
NSString * title = [NSString stringWithFormat:
NSLocalizedString(@"All filesystems mounted", @"FS Mount Success all")];
[self notifySuccessWithTitle:title text:nil];
}
[self handleFileSystemChangeReply:error];
}];
}

- (IBAction)mountFilesystem:(id)sender
{
NSDictionary * opts = @{@"filesystem": [sender representedObject]};
Expand Down

0 comments on commit ecd5faf

Please sign in to comment.