except cephfs.Error as e:
raise IndexException(-e.args[0], e.args[1])
+ def list_entries_by_ctime_order(self):
+ entry_names = listdir(self.fs, self.path, filter_files=False)
+ if not entry_names:
+ return []
+
+ # clone entries with ctime obtained by statig them. basically,
+ # following is a list of tuples where each tuple has 2 memebers.
+ ens_with_ctime = []
+ for en in entry_names:
+ d_path = os.path.join(self.path, en)
+ stb = self.fs.lstat(d_path)
+
+ # add ctime next to clone entry
+ ens_with_ctime.append((en, stb.st_ctime))
+
+ ens_with_ctime.sort(key=lambda ctime: en[1])
+
+ # remove ctime and return list of clone entries sorted by ctime.
+ return [i[0] for i in ens_with_ctime]
+
def get_oldest_clone_entry(self, exclude=[]):
- min_ctime_entry = None
- exclude_tracking_ids = [v[0] for v in exclude]
- log.debug("excluded tracking ids: {0}".format(exclude_tracking_ids))
- for entry in list_one_entry_at_a_time(self.fs, self.path):
- dname = entry.d_name
- dpath = os.path.join(self.path, dname)
- st = self.fs.lstat(dpath)
- if dname not in exclude_tracking_ids and stat.S_ISLNK(st.st_mode):
- if min_ctime_entry is None or st.st_ctime < min_ctime_entry[1].st_ctime:
- min_ctime_entry = (dname, st)
- if min_ctime_entry:
- try:
+ try:
+ min_ctime_entry = None
+ exclude_tracking_ids = [v[0] for v in exclude]
+ log.debug("excluded tracking ids: {0}".format(exclude_tracking_ids))
+ for entry in list_one_entry_at_a_time(self.fs, self.path):
+ dname = entry.d_name
+ dpath = os.path.join(self.path, dname)
+ st = self.fs.lstat(dpath)
+ if dname not in exclude_tracking_ids and stat.S_ISLNK(st.st_mode):
+ if min_ctime_entry is None or st.st_ctime < min_ctime_entry[1].st_ctime:
+ min_ctime_entry = (dname, st)
+ if min_ctime_entry:
linklen = min_ctime_entry[1].st_size
- sink_path = self.fs.readlink(os.path.join(self.path, min_ctime_entry[0]), CloneIndex.PATH_MAX)
+ sink_path = self.fs.readlink(os.path.join(self.path, min_ctime_entry[0]), PATH_MAX)
return (min_ctime_entry[0], sink_path[:linklen])
- except cephfs.Error as e:
- raise IndexException(-e.args[0], e.args[1])
- return None
+ return None
+ except cephfs.Error as e:
+ log.debug('Exception cephfs.Error has been caught. Printing '
+ f'the exception - {e}')
+ raise IndexException(-e.args[0], e.args[1])
def find_clone_entry_index(self, sink_path):
try: