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
9 changes: 9 additions & 0 deletions tests/test_anim_glb.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,15 @@ def test_outputs_over_an_input_are_refused(self):
"--part", hex(self.offsets[1]), "--report", self.packs)
self.assertEqual(r.returncode, 2)

def test_same_nonexistent_glb_and_report_paths_are_refused(self):
out = os.path.join(self.tmp.name, "not-created", "same.glb")
r = self.run_tool(self.packs, out, "--skeleton", hex(self.offsets[0]), "--part", hex(self.offsets[1]),
"--report", out)
self.assertEqual(r.returncode, 2, r.stderr)
self.assertIn("the GLB and the report are the same path", r.stderr)
self.assertFalse(os.path.exists(out))
self.assertFalse(os.path.exists(os.path.dirname(out)))

def test_report_directory_is_refused_before_writing_a_glb(self):
out = os.path.join(self.tmp.name, "out.glb")
report = os.path.join(self.tmp.name, "report")
Expand Down
13 changes: 2 additions & 11 deletions tools/anim_clips.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import anim_index # noqa: E402
from pool_workers import process_workers # noqa: E402
from report_paths import same_report_path # noqa: E402

SYSTEM = 0x50000000
CHANNEL_NAMES = ("static_quat", "static_vec3", "static_float", "raw_float", "quantize_float",
Expand Down Expand Up @@ -1519,16 +1520,6 @@ def decode_one(path, offset, frames):
return d


def same_output_path(first, second):
"""True when writing ``second`` would truncate ``first`` (same file, path or hard link)."""
if os.path.normcase(os.path.realpath(first)) == os.path.normcase(os.path.realpath(second)):
return True
try:
return os.path.samefile(first, second)
except OSError:
return False


def main():
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("archive", help="anim.rpf")
Expand All @@ -1554,7 +1545,7 @@ def main():
if a.out:
if os.path.isdir(a.out):
ap.error(f"{a.out} is a directory, not a .json file")
if same_output_path(a.archive, a.out):
if same_report_path(a.archive, a.out):
ap.error("output must not overwrite the input archive")
try:
if a.decode is not None:
Expand Down
9 changes: 3 additions & 6 deletions tools/anim_glb.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
from file_mode import published_mode # noqa: E402
import glb_writer # noqa: E402
from pool_workers import process_workers # noqa: E402
from report_paths import same_report_path # noqa: E402
import skin_streams # noqa: E402

SYSTEM = 0x50000000
Expand Down Expand Up @@ -618,10 +619,6 @@ def parse_offset(text):
raise argparse.ArgumentTypeError(f"not an offset: {text!r}") from None


def same_path(first, second):
return anim_clips.same_output_path(first, second)


def export(args):
started = time.monotonic()
report = {"archive": os.path.basename(args.archive), "parts": [], "clips": [], "counts": collections.Counter()}
Expand Down Expand Up @@ -772,11 +769,11 @@ def main(argv=None):
outputs = [p for p in (args.out, args.report) if p]
for o in outputs:
for i in inputs:
if os.path.exists(o) and same_path(i, o):
if os.path.exists(o) and same_report_path(i, o):
ap.error(f"{o} is an input; refusing to overwrite it")
if args.report and os.path.isdir(args.report):
ap.error(f"--report is a directory: {args.report}")
if args.out and args.report and same_path(args.out, args.report):
if args.out and args.report and same_report_path(args.out, args.report):
ap.error("the GLB and the report are the same path")
if args.clip or args.dictionary is not None:
if args.coverage:
Expand Down
Loading