worker: avoid potential partial write of pickled data
Previously, the code wrote the pickled data using os.write(). However,
os.write() can write less bytes than passed to it. To trigger the problem, the
pickled data had to be larger than
2147479552 bytes on my system.
Instead, open a file object and pass it to pickle.dump(). This also has the
advantage that it doesn’t buffer the whole pickled data in memory.
Note that the opened file must be buffered because pickle doesn’t support
unbuffered streams because unbuffered streams’ write() method might write less
bytes than passed to it (like os.write()) but pickle.dump() relies on that all
bytes are written (see https://github.com/python/cpython/issues/93050).
The side effect of using a file object and a with statement is that wfd is
explicitly closed now while it seems like before it was implicitly closed by
process exit.
#require test-repo hg10
$ . "$TESTDIR/helpers-testrepo.sh"
$ cat > $TESTTMP/check_ascii.py <<EOF
> import sys
> for file_path in sys.argv[1:]:
> with open(file_path, 'br') as f:
> try:
> f.read().decode('ascii', 'strict')
> except UnicodeDecodeError as exc:
> print('%s: %s' % (file_path, exc))
> EOF
There are some web servers in the wild that can serve static files with an
incorrect encoding (e.g. https://bz.mercurial-scm.org/show_bug.cgi?id=6559).
One way to prevent any issues is to not use any non-ASCII characters, e.g.
URL-encoding them or using HTML entities.
check charset of all tracked files ending in .js
$ cd "`dirname "$TESTDIR"`"
$ testrepohg locate 'set:**.js' \
> 2>/dev/null \
> | xargs "$PYTHON" $TESTTMP/check_ascii.py