Skip to content
Merged
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 sqlmesh/utils/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def __init__(self, path: Path, prefix: t.Optional[str] = None):
threshold = to_datetime("1 week ago").timestamp()
# delete all old cache files
for file in self._path.glob("*"):
if IS_WINDOWS:
# the file.stat() call below will fail on windows if the :file name is longer than 260 chars
file = fix_windows_path(file)

if not file.stem.startswith(self._cache_version) or file.stat().st_atime < threshold:
file.unlink(missing_ok=True)

Expand Down
14 changes: 13 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,19 @@ def _make_function(
# shutil.copytree just doesnt work properly with the symlinks on Windows, regardless of the `symlinks` setting
src = str(path.absolute())
dst = str(temp_dir.absolute())
os.system(f"robocopy {src} {dst} /E /COPYALL")

# Robocopy flag reference: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy#copy-options
# /E: Copy subdirectories, including empty directories
# /COPY:D Copy "data" only. In particular, this avoids copying auditing information, which can throw
# an error like "ERROR : You do not have the Manage Auditing user right"
robocopy_cmd = f"robocopy {src} {dst} /E /COPY:D"
exit_code = os.system(robocopy_cmd)

# exit code reference: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy#exit-return-codes
if exit_code > 8:
raise Exception(
f"robocopy command: '{robocopy_cmd}' failed with exit code: {exit_code}"
)

# after copying, delete the files that would have been ignored
for root, dirs, _ in os.walk(temp_dir):
Expand Down