MCPcopy Create free account
hub / github.com/FastLED/FastLED / write_if_different

Function write_if_different

ci/meson/io_utils.py:49–85  ·  view source on GitHub ↗

Write file only if content differs from existing file. This prevents unnecessary file modifications that would trigger Meson regeneration. If the file doesn't exist or content has changed, writes the new content atomically. Args: path: Path to file to write con

(path: Path, content: str, mode: Optional[int] = None)

Source from the content-addressed store, hash-verified

47
48
49def write_if_different(path: Path, content: str, mode: Optional[int] = None) -> bool:
50 """
51 Write file only if content differs from existing file.
52
53 This prevents unnecessary file modifications that would trigger Meson
54 regeneration. If the file doesn't exist or content has changed, writes
55 the new content atomically.
56
57 Args:
58 path: Path to file to write
59 content: Content to write
60 mode: Optional file permissions (Unix only)
61
62 Returns:
63 True if file was written (created or modified), False if unchanged
64 """
65 try:
66 if path.exists():
67 existing_content = path.read_text(encoding="utf-8")
68 if existing_content == content:
69 return False # Content unchanged, skip write
70
71 # Content changed or file doesn't exist - write it atomically
72 atomic_write_text(path, content)
73
74 # Set permissions if specified (Unix only)
75 if mode is not None and not sys.platform.startswith("win"):
76 path.chmod(mode)
77
78 return True
79 except (OSError, IOError) as e:
80 # On error, try to write anyway - caller will handle failures
81 _ts_print(f"[MESON] Warning: Error checking file {path}: {e}")
82 atomic_write_text(path, content)
83 if mode is not None and not sys.platform.startswith("win"):
84 path.chmod(mode)
85 return True

Callers 1

write_meson_native_fileFunction · 0.90

Calls 1

atomic_write_textFunction · 0.85

Tested by

no test coverage detected