Skip to content

Commit f02ded0

Browse files
committed
Chore: Fix windows tests
1 parent 8e9fe23 commit f02ded0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

sqlmesh/utils/cache.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def __init__(self, path: Path, prefix: t.Optional[str] = None):
5959
threshold = to_datetime("1 week ago").timestamp()
6060
# delete all old cache files
6161
for file in self._path.glob("*"):
62+
if IS_WINDOWS:
63+
# the file.stat() call below will fail on windows if the :file name is longer than 260 chars
64+
file = fix_windows_path(file)
65+
6266
if not file.stem.startswith(self._cache_version) or file.stat().st_atime < threshold:
6367
file.unlink(missing_ok=True)
6468

tests/conftest.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,19 @@ def _make_function(
580580
# shutil.copytree just doesnt work properly with the symlinks on Windows, regardless of the `symlinks` setting
581581
src = str(path.absolute())
582582
dst = str(temp_dir.absolute())
583-
os.system(f"robocopy {src} {dst} /E /COPYALL")
583+
584+
# Robocopy flag reference: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy#copy-options
585+
# /E: Copy subdirectories, including empty directories
586+
# /COPY:D Copy "data" only. In particular, this avoids copying auditing information, which can throw
587+
# an error like "ERROR : You do not have the Manage Auditing user right"
588+
robocopy_cmd = f"robocopy {src} {dst} /E /COPY:D"
589+
exit_code = os.system(robocopy_cmd)
590+
591+
# exit code reference: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy#exit-return-codes
592+
if exit_code > 8:
593+
raise Exception(
594+
f"robocopy command: '{robocopy_cmd}' failed with exit code: {exit_code}"
595+
)
584596

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

0 commit comments

Comments
 (0)