From 81b4721ea8785150e718b923bdf1d7a5651ad89d Mon Sep 17 00:00:00 2001 From: Onno Broekmans Date: Tue, 18 Apr 2017 22:00:58 +0200 Subject: [PATCH 1/3] Deal correctly with Windows line endings Convert Windows line endings into Unix ones, for correct processing downstream. --- latexrun | 2 ++ 1 file changed, 2 insertions(+) diff --git a/latexrun b/latexrun index b669d9f..0c64454 100755 --- a/latexrun +++ b/latexrun @@ -833,6 +833,8 @@ class LaTeX(Task): data = os.read(stdout.fileno(), 4096) if not data: break + if os.name == 'nt': + data = data.replace(b'\r', b'') # See "A note about encoding" above data = data.decode('ascii', errors='surrogateescape') buf.append(data) From 06dcce0918ff4328b7400d7e448e0110eed8bfb3 Mon Sep 17 00:00:00 2001 From: Onno Broekmans Date: Tue, 18 Apr 2017 22:03:01 +0200 Subject: [PATCH 2/3] Fix atomic file commits `os.rename` doesn't behave correctly on Windows, and causes a `WinError` exception. `os.replace` seems to be the better way to do atomic renames, and also works on Windows. --- latexrun | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/latexrun b/latexrun index 0c64454..5c40a56 100755 --- a/latexrun +++ b/latexrun @@ -279,7 +279,7 @@ class DB: json.dump(self.__val, fp, indent=2, separators=(',', ': ')) fp.flush() os.fsync(fp.fileno()) - os.rename(tmp_filename, self.__filename) + os.replace(tmp_filename, self.__filename) def get_summary(self, task_id): """Return the recorded summary for the given task or None.""" @@ -1044,7 +1044,7 @@ class LaTeXCommit(Task): else: debug('commiting {} to {}', outname, commit) shutil.copy(outname, outname + '~') - os.rename(outname + '~', commit) + os.replace(outname + '~', commit) except OSError as e: raise TaskError('error committing latex output: {}'.format(e)) from e self._input('file', outname) From 0b5166eeea07620f16e94b40e69f21d8eff6f9a0 Mon Sep 17 00:00:00 2001 From: Onno Broekmans Date: Tue, 18 Apr 2017 22:04:26 +0200 Subject: [PATCH 3/3] Fix absolute path detection on Windows Use `os.path.isabs` instead of manually detecting an initial forward slash. This also works on Windows. --- latexrun | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/latexrun b/latexrun index 5c40a56..b287125 100755 --- a/latexrun +++ b/latexrun @@ -913,7 +913,7 @@ class LaTeX(Task): if parts[0] == 'PWD': pwd = parts[1] elif parts[0] in ('INPUT', 'OUTPUT'): - if parts[1].startswith('/'): + if os.path.isabs(parts[1]): path = parts[1] else: # Try to make "nice" paths, especially for clean @@ -1685,7 +1685,7 @@ class BibTeX(Task): # If this path is relative to the source directory, # clean it up for error reporting and portability of # the dependency DB - if filename.startswith('/'): + if os.path.isabs(filename): relname = os.path.relpath(filename) if '../' not in relname: filename = relname