Skip to content

Commit

Permalink
Merge pull request #784 from kush-gupt/main
Browse files Browse the repository at this point in the history
Check if file exists before sorting them into a list
  • Loading branch information
maxamillion authored Feb 11, 2025
2 parents d13d02b + db5ec02 commit d9e6630
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ramalama/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def human_duration(d):
return f"{d // 31536000} years"


def list_files_by_modification():
def list_files_by_modification(args):
paths = Path().rglob("*")
models = []
for path in paths:
Expand All @@ -438,7 +438,11 @@ def list_files_by_modification():
path = str(path).replace("file/", "file:///")
perror(f"{path} does not exist")
continue
models.append(path)
if os.path.exists(path):
models.append(path)
else:
print(f"Broken symlink found in: {args.store}/models/{path} \nAttempting removal")
New(str(path).replace("/", "://", 1), args).remove(args)

return sorted(models, key=lambda p: os.path.getmtime(p), reverse=True)

Expand Down Expand Up @@ -536,7 +540,7 @@ def _list_models(args):
models = []

# Collect model data
for path in list_files_by_modification():
for path in list_files_by_modification(args):
if path.is_symlink():
if str(path).startswith("file/"):
name = str(path).replace("/", ":///", 1)
Expand Down

0 comments on commit d9e6630

Please sign in to comment.