|
6 | 6 | # Home: https://github.com/JavaScriptDude/zfslib |
7 | 7 | # Licence: https://opensource.org/licenses/BSD-3-Clause |
8 | 8 | # TODO: |
| 9 | +# [.] In meld mode, handle ctrl-C (KeyboardInterrupt) gracefully |
9 | 10 | # [.] Allow querying of just zpool properties only rather than digging all zfs list -t all for every call |
10 | 11 | # - This will make it much faster for such queries |
11 | 12 | ######################################### |
@@ -237,27 +238,25 @@ def remove(self, name): # takes a NAME, unlike the child that is taken in the r |
237 | 238 | del self._pools[name] |
238 | 239 |
|
239 | 240 |
|
240 | | - # Will resolve Pool and Dataset for a path on local filesystem using the mountpoint |
241 | | - # returns (Pool, Dataset, Real_Path, Relative_Path) |
| 241 | + # resolve Pool and Dataset for a path on local filesystem using the mountpoint |
242 | 242 | # Note: Ignores any dataset with root mountpoint (/) |
| 243 | + # eg: (dataset, real_path, rel_path) = find_dataset_for_path('/dpool/foo/bar/baz.sh') |
243 | 244 | def find_dataset_for_path(self, path): |
244 | 245 | assert self.have_mounts, "Mount information not loaded. Please use Connection.load_poolset(get_mounts=True)." |
245 | 246 | p_real = os.path.abspath( expand_user(path) ) |
246 | 247 | p_real = os.path.realpath(p_real) |
247 | | - pool=ds=mp=p_rela=None |
| 248 | + mp=None |
248 | 249 | for pool_c in self: |
249 | 250 | datasets = pool_c.get_all_datasets() |
250 | 251 | for ds_c in datasets: |
251 | | - if not ds_c.has_mount or ds_c.mountpoint == '/': continue |
252 | | - mp_c = ds_c.mountpoint |
253 | | - if p_real.find(mp_c) == 0: |
254 | | - if mp is None or len(mp_c) > len(mp): |
255 | | - p_rela = p_real.replace(mp_c, '') |
256 | | - ds = ds_c |
257 | | - pool = pool_c |
258 | | - mp = mp_c |
| 252 | + if not ds_c.has_mount \ |
| 253 | + or ds_c.mountpoint is None \ |
| 254 | + or ds_c.mountpoint == '/': continue |
| 255 | + if p_real.find(ds_c.mountpoint) == 0: |
| 256 | + if mp is None or len(ds_c.mountpoint) > len(mp): |
| 257 | + return (ds_c, p_real, p_real.replace(ds_c.mountpoint, '')) |
259 | 258 |
|
260 | | - return (ds, p_real, p_rela) |
| 259 | + return (None, None, None) |
261 | 260 |
|
262 | 261 |
|
263 | 262 | def __getitem__(self, name): |
|
0 commit comments