##// END OF EJS Templates
posix: always seek to EOF when opening a file in append mode...
posix: always seek to EOF when opening a file in append mode Python 3 already does this, so skip it there. Consider the program: #include <stdio.h> int main() { FILE *f = fopen("narf", "w"); fprintf(f, "narf\n"); fclose(f); f = fopen("narf", "a"); printf("%ld\n", ftell(f)); fprintf(f, "troz\n"); printf("%ld\n", ftell(f)); return 0; } on macOS, FreeBSD, and Linux with glibc, this program prints 5 10 but on musl libc (Alpine Linux and probably others) this prints 0 10 By my reading of https://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html this is technically correct, specifically: > Opening a file with append mode (a as the first character in the > mode argument) shall cause all subsequent writes to the file to be > forced to the then current end-of-file, regardless of intervening > calls to fseek(). in other words, the file position doesn't really matter in append-mode files, and we can't depend on it being at all meaningful unless we perform a seek() before tell() after open(..., 'a'). Experimentally after a .write() we can do a .tell() and it'll always be reasonable, but I'm unclear from reading the specification if that's a smart thing to rely on. This matches what we do on Windows and what Python 3 does for free, so let's just be consistent. Thanks to Yuya for the idea.

File last commit:

r39687:a641fd1a default
r43163:97ada9b8 5.0.2 stable
Show More
accept-4564.json
138 lines | 7.0 KiB | application/json | JsonLexer
{
"version": 1,
"interactions": [
{
"request": {
"body": "api.token=cli-hahayouwish&ids%5B0%5D=4564",
"headers": {
"content-length": [
"58"
],
"content-type": [
"application/x-www-form-urlencoded"
],
"host": [
"phab.mercurial-scm.org"
],
"accept": [
"application/mercurial-0.1"
],
"user-agent": [
"mercurial/proto-1.0 (Mercurial 4.7.1+861-aa7e312375cf)"
]
},
"method": "POST",
"uri": "https://phab.mercurial-scm.org//api/differential.query"
},
"response": {
"status": {
"message": "OK",
"code": 200
},
"headers": {
"expires": [
"Sat, 01 Jan 2000 00:00:00 GMT"
],
"x-content-type-options": [
"nosniff"
],
"set-cookie": [
"phsid=A%2F24j2baem5tmap4tvfdz7ufmca2lhm3wx4agyqv4w; expires=Thu, 14-Sep-2023 04:24:35 GMT; Max-Age=157680000; path=/; domain=phab.mercurial-scm.org; secure; httponly"
],
"strict-transport-security": [
"max-age=0; includeSubdomains; preload"
],
"server": [
"Apache/2.4.10 (Debian)"
],
"connection": [
"close"
],
"x-xss-protection": [
"1; mode=block"
],
"cache-control": [
"no-store"
],
"date": [
"Sat, 15 Sep 2018 04:24:35 GMT"
],
"x-frame-options": [
"Deny"
],
"content-type": [
"application/json"
]
},
"body": {
"string": "{\"result\":[{\"id\":\"4564\",\"phid\":\"PHID-DREV-6cgnf5fyeeqhntbxgfb7\",\"title\":\"localrepo: move some vfs initialization out of __init__\",\"uri\":\"https:\\/\\/phab.mercurial-scm.org\\/D4564\",\"dateCreated\":\"1536856174\",\"dateModified\":\"1536856175\",\"authorPHID\":\"PHID-USER-p54bpwbifxx7sbgpx47d\",\"status\":\"0\",\"statusName\":\"Needs Review\",\"properties\":[],\"branch\":null,\"summary\":\"In order to make repository types more dynamic, we'll need to move the\\nlogic for determining repository behavior out of\\nlocalrepository.__init__ so we can influence behavior before the type\\nis instantiated.\\n\\nThis commit starts that process by moving working directory and .hg\\/\\nvfs initialization to our new standalone function for instantiating\\nlocal repositories.\\n\\nAside from API changes, behavior should be fully backwards compatible.\\n\\n.. api::\\n\\n localrepository.__init__ now does less work and accepts new args\\n\\n Use ``hg.repository()``, ``localrepo.instance()``, or\\n ``localrepo.makelocalrepository()`` to obtain a new local repository\\n instance instead of calling the ``localrepository`` constructor\\n directly.\",\"testPlan\":\"\",\"lineCount\":\"64\",\"activeDiffPHID\":\"PHID-DIFF-ir6bizkdou7fm7xhuo6v\",\"diffs\":[\"11002\"],\"commits\":[],\"reviewers\":{\"PHID-PROJ-3dvcxzznrjru2xmmses3\":\"PHID-PROJ-3dvcxzznrjru2xmmses3\"},\"ccs\":[\"PHID-USER-q42dn7cc3donqriafhjx\"],\"hashes\":[],\"auxiliary\":{\"phabricator:projects\":[],\"phabricator:depends-on\":[\"PHID-DREV-gqp33hnxg65vkl3xioka\"]},\"repositoryPHID\":\"PHID-REPO-bvunnehri4u2isyr7bc3\"}],\"error_code\":null,\"error_info\":null}"
}
}
},
{
"request": {
"body": "api.token=cli-hahayouwish&objectIdentifier=PHID-DREV-6cgnf5fyeeqhntbxgfb7&transactions%5B0%5D%5Btype%5D=accept&transactions%5B0%5D%5Bvalue%5D=true&transactions%5B1%5D%5Btype%5D=comment&transactions%5B1%5D%5Bvalue%5D=I+think+I+like+where+this+is+headed.+Will+read+rest+of+series+later.",
"headers": {
"content-length": [
"301"
],
"content-type": [
"application/x-www-form-urlencoded"
],
"host": [
"phab.mercurial-scm.org"
],
"accept": [
"application/mercurial-0.1"
],
"user-agent": [
"mercurial/proto-1.0 (Mercurial 4.7.1+861-aa7e312375cf)"
]
},
"method": "POST",
"uri": "https://phab.mercurial-scm.org//api/differential.revision.edit"
},
"response": {
"status": {
"message": "OK",
"code": 200
},
"headers": {
"expires": [
"Sat, 01 Jan 2000 00:00:00 GMT"
],
"x-content-type-options": [
"nosniff"
],
"set-cookie": [
"phsid=A%2Fcna7xx3xon5xxyoasbveqlfz4fswd2risihw7dff; expires=Thu, 14-Sep-2023 04:24:36 GMT; Max-Age=157680000; path=/; domain=phab.mercurial-scm.org; secure; httponly"
],
"strict-transport-security": [
"max-age=0; includeSubdomains; preload"
],
"server": [
"Apache/2.4.10 (Debian)"
],
"x-xss-protection": [
"1; mode=block"
],
"cache-control": [
"no-store"
],
"date": [
"Sat, 15 Sep 2018 04:24:36 GMT"
],
"x-frame-options": [
"Deny"
],
"content-type": [
"application/json"
]
},
"body": {
"string": "{\"result\":{\"object\":{\"id\":\"4564\",\"phid\":\"PHID-DREV-6cgnf5fyeeqhntbxgfb7\"},\"transactions\":[{\"phid\":\"PHID-XACT-DREV-nfqswjwwfuzdrhb\"},{\"phid\":\"PHID-XACT-DREV-oqb5pkqsdify6nm\"},{\"phid\":\"PHID-XACT-DREV-i6epvc7avyv3ve7\"},{\"phid\":\"PHID-XACT-DREV-du5hbg5rege3i5w\"}]},\"error_code\":null,\"error_info\":null}"
}
}
}
]
}