Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@
## 2026-06-25 - [Optimize Path.exists() when paired with stat()]
**Learning:** Checking `Path.exists()` before `Path.stat()` introduces a redundant system call because `exists()` internally uses `stat()`.
**Action:** Rely on catching the `OSError` from `Path.stat()` to simultaneously check for existence and retrieve file attributes, saving measurable I/O overhead on large filesystems.

## 2024-05-24 - [Avoid excessive .resolve() for subprocess arguments]
**Learning:** `pathlib.Path.resolve()` performs heavy disk I/O to check for symlinks and build a canonical path. When passing paths to external binaries (like `ffmpeg`, `setfile`, `brctl`) via `subprocess.run`, strict canonicalization is generally unnecessary because OS APIs and external tools handle relative paths, `..`, and symlinks natively.
**Action:** Prefer `pathlib.Path.absolute()` over `pathlib.Path.resolve()` when building command-line arguments for external tools to save fractions of a millisecond, though recognize this is a micro-optimization and focus on larger architectural bottlenecks first.
8 changes: 4 additions & 4 deletions media_shrinker.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def command(
raise MediaShrinkerError(
"ffmpeg argument template is missing '-i'"
) from exc
args[input_index] = str(input_path.resolve())
args[input_index] = str(input_path.absolute())
if output_path is not None:
args[-1] = str(output_path.resolve())
args[-1] = str(output_path.absolute())

if overwrite:
args = ["-y" if arg == "-n" else arg for arg in args]
Expand Down Expand Up @@ -633,7 +633,7 @@ def build_icloud_download_command(
) -> list[str]:
"""Build a safe iCloud download command for source_path."""

return [brctl_path, "download", str(source_path.resolve())]
return [brctl_path, "download", str(source_path.absolute())]


def download_from_icloud(source_path: Path, *, brctl_path: str = "brctl") -> None:
Expand Down Expand Up @@ -1630,7 +1630,7 @@ def _copy_macos_creation_time(
"%m/%d/%Y %H:%M:%S"
)
subprocess.run(
[setfile_path, "-d", creation_date, str(dest.resolve())],
[setfile_path, "-d", creation_date, str(dest.absolute())],
check=False,
capture_output=True,
text=True,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_media_shrinker.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ def test_conversion_command_resolves_input_and_output_overrides(self) -> None:

self.assertEqual(
command[command.index("-i") + 1],
str(Path("-input.wav").resolve()),
str(Path("-input.wav").absolute()),
)
self.assertEqual(command[-1], str(Path("-output.flac").resolve()))
self.assertEqual(command[-1], str(Path("-output.flac").absolute()))

def test_lossy_audio_uses_highest_opus_bitrate_that_fits_target_with_safety_margin(
self,
Expand Down Expand Up @@ -1042,7 +1042,7 @@ def test_build_icloud_download_command_uses_argument_list_for_paths_with_spaces(

self.assertEqual(
command,
["brctl", "download", str(Path("folder/file with spaces.m4a").resolve())],
["brctl", "download", str(Path("folder/file with spaces.m4a").absolute())],
)


Expand Down
Loading