Skip to content

Conversation

@mattt
Copy link
Collaborator

@mattt mattt commented Nov 4, 2025

Follow-up to #2

@mattt mattt requested a review from Copilot November 4, 2025 16:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for downloading repository snapshots locally with caching capabilities. The implementation includes metadata tracking to avoid re-downloading unchanged files and support for glob pattern filtering.

  • Introduces downloadSnapshot method to download complete repository snapshots with progress tracking
  • Adds LocalDownloadFileMetadata structure to track download metadata (commit hash, etag, timestamp)
  • Implements metadata persistence and validation helpers using file-based storage

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
Sources/HuggingFace/Hub/HubClient+Files.swift Adds snapshot download functionality, metadata helpers, and file hashing utilities; marks several unused parameters with underscore prefix
Sources/HuggingFace/Hub/File.swift Defines LocalDownloadFileMetadata struct and removes self. prefix in FileBatch.init()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -1,3 +1,4 @@
import CryptoKit
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

The CryptoKit import is unused in this file. The LocalDownloadFileMetadata struct only stores metadata as strings and does not perform any cryptographic operations. Consider removing this import since SHA256 is only used in HubClient+Files.swift where it's already imported.

Suggested change
import CryptoKit

Copilot uses AI. Check for mistakes.
.filter { filename in
guard !globs.isEmpty else { return true }
return globs.contains { glob in
fnmatch(glob, filename, 0) == 0
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

The fnmatch function is a C library function that may not be available on all platforms (requires Darwin on Apple platforms or Glibc on Linux). Consider adding appropriate platform-specific imports (#if canImport(Darwin) import Darwin #elseif canImport(Glibc) import Glibc #endif) at the top of the file to ensure cross-platform compatibility, or document platform requirements if this is intentionally platform-specific.

Copilot uses AI. Check for mistakes.
}

if Task.isCancelled {
return repoDestination
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

When a task is cancelled, returning normally may lead to incomplete downloads being treated as successful. Consider throwing a CancellationError instead of returning the destination URL to properly signal the cancellation state: throw CancellationError().

Suggested change
return repoDestination
throw CancellationError()

Copilot uses AI. Check for mistakes.
Comment on lines +615 to +618
let filename = metadataPath.lastPathComponent.replacingOccurrences(
of: ".metadata",
with: ""
)
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

Using replacingOccurrences(of:with:) for extracting the filename is fragile. If a file legitimately contains '.metadata' in its name (e.g., 'model.metadata.json'), this will incorrectly strip that portion. Use deletingPathExtension() if '.metadata' is truly an extension, or String.removingSuffix() to only remove the suffix if it exists at the end.

Copilot uses AI. Check for mistakes.
@mattt mattt merged commit 43c25ac into main Nov 4, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants