Skip to content

Commit

Permalink
follow-cvelist.py Windows compatibility
Browse files Browse the repository at this point in the history
- Define explicitly that README.md has UTF-8 encoding.
- Convert Windows paths to POSIX before passing them to git.
  • Loading branch information
oh2fih committed Aug 10, 2024
1 parent d5c7a1f commit 746c860
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions bin/follow-cvelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,17 +448,18 @@ def changed_files(self, current_commit: str, past_commit: str) -> List[bytes]:
def json_at_commit(self, path: Path, commit: str) -> Any:
"""Dictionary of JSON file contents at given commit"""
try:
pathstr = path.as_posix() # for Windows compatibility
result = subprocess.run(
["git", "show", f"{commit}:{path}"], stdout=subprocess.PIPE
["git", "show", f"{commit}:{pathstr}"], stdout=subprocess.PIPE
)
data = json.loads(result.stdout.decode("utf-8"))
if self.args.verbose > 3:
print(f"[{commit}:{path}] {data}", file=sys.stderr)
print(f"[{commit}:{pathstr}] {data}", file=sys.stderr)
return data
except IOError:
print(f"Could not open {commit}:{path}", file=sys.stderr)
print(f"Could not open {commit}:{pathstr}", file=sys.stderr)
except json.decoder.JSONDecodeError:
print(f"Could not parse {commit}:{path}", file=sys.stderr)
print(f"Could not parse {commit}:{pathstr}", file=sys.stderr)
return {}

def cvelist_repo(self) -> bool:
Expand All @@ -471,7 +472,7 @@ def cvelist_repo(self) -> bool:
working = Path(os.getcwd())

if os.path.samefile(str(toplevel), str(working)):
readmefile = open("README.md", "r")
readmefile = open("README.md", "r", encoding="utf-8")
readme = readmefile.readlines()
readmefile.close()
for line in readme:
Expand Down

0 comments on commit 746c860

Please sign in to comment.