| 1 |
#require execbit unix-permissions no-chg |
| 2 |
|
| 3 |
Checking that experimental.atomic-file works. |
| 4 |
|
| 5 |
$ cat > $TESTTMP/show_mode.py <<EOF |
| 6 |
> import os |
| 7 |
> import stat |
| 8 |
> import sys |
| 9 |
> ST_MODE = stat.ST_MODE |
| 10 |
> |
| 11 |
> for file_path in sys.argv[1:]: |
| 12 |
> file_stat = os.stat(file_path) |
| 13 |
> octal_mode = oct(file_stat[ST_MODE] & 0o777).replace('o', '') |
| 14 |
> print("%s:%s" % (file_path, octal_mode)) |
| 15 |
> |
| 16 |
> EOF |
| 17 |
|
| 18 |
$ hg init repo |
| 19 |
$ cd repo |
| 20 |
|
| 21 |
$ cat > .hg/showwrites.py <<EOF |
| 22 |
> from mercurial import pycompat |
| 23 |
> from mercurial.utils import stringutil |
| 24 |
> def uisetup(ui): |
| 25 |
> from mercurial import merge, vfs |
| 26 |
> merge.MAYBE_USE_RUST_UPDATE = False |
| 27 |
> class newvfs(vfs.vfs): |
| 28 |
> def __call__(self, *args, **kwargs): |
| 29 |
> print(pycompat.sysstr(stringutil.pprint( |
| 30 |
> ('vfs open', args, sorted(list(kwargs.items())))))) |
| 31 |
> return super(newvfs, self).__call__(*args, **kwargs) |
| 32 |
> vfs.vfs = newvfs |
| 33 |
> EOF |
| 34 |
|
| 35 |
$ for v in a1 a2 b1 b2 c ro; do echo $v > $v; done |
| 36 |
$ chmod +x b* |
| 37 |
$ hg commit -Aqm _ |
| 38 |
|
| 39 |
# We check that |
| 40 |
# - the changes are actually atomic |
| 41 |
# - that permissions are correct (all 4 cases of (executable before) * (executable after)) |
| 42 |
# - that renames work, though they should be atomic anyway |
| 43 |
# - that it works when source files are read-only (but directories are read-write still) |
| 44 |
|
| 45 |
$ for v in a1 a2 b1 b2 ro; do echo changed-$v > $v; done |
| 46 |
$ chmod -x *1; chmod +x *2 |
| 47 |
$ hg rename c d |
| 48 |
$ hg commit -qm _ |
| 49 |
|
| 50 |
Check behavior without update.atomic-file |
| 51 |
|
| 52 |
$ hg update -r 0 -q |
| 53 |
$ hg update -r 1 --config extensions.showwrites=.hg/showwrites.py 2>&1 | grep "a1'.*wb" |
| 54 |
('vfs open', ('a1', 'wb'), [('atomictemp', False), ('backgroundclose', True)]) |
| 55 |
|
| 56 |
$ "$PYTHON" $TESTTMP/show_mode.py * |
| 57 |
a1:0644 |
| 58 |
a2:0755 |
| 59 |
b1:0644 |
| 60 |
b2:0755 |
| 61 |
d:0644 |
| 62 |
ro:0644 |
| 63 |
|
| 64 |
Add a second revision for the ro file so we can test update when the file is |
| 65 |
present or not |
| 66 |
|
| 67 |
$ echo "ro" > ro |
| 68 |
|
| 69 |
$ hg commit -qm _ |
| 70 |
|
| 71 |
Check behavior without update.atomic-file first |
| 72 |
|
| 73 |
$ hg update -C -r 0 -q |
| 74 |
|
| 75 |
$ hg update -r 1 |
| 76 |
6 files updated, 0 files merged, 1 files removed, 0 files unresolved |
| 77 |
|
| 78 |
$ "$PYTHON" $TESTTMP/show_mode.py * |
| 79 |
a1:0644 |
| 80 |
a2:0755 |
| 81 |
b1:0644 |
| 82 |
b2:0755 |
| 83 |
d:0644 |
| 84 |
ro:0644 |
| 85 |
|
| 86 |
Manually reset the mode of the read-only file |
| 87 |
|
| 88 |
$ chmod a-w ro |
| 89 |
|
| 90 |
$ "$PYTHON" $TESTTMP/show_mode.py ro |
| 91 |
ro:0444 |
| 92 |
|
| 93 |
Now the file is present, try to update and check the permissions of the file |
| 94 |
|
| 95 |
$ hg up -r 2 |
| 96 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 97 |
|
| 98 |
$ "$PYTHON" $TESTTMP/show_mode.py ro |
| 99 |
ro:0644 |
| 100 |
|
| 101 |
# The file which was read-only is now writable in the default behavior |
| 102 |
|
| 103 |
Check behavior with update.atomic-files |
| 104 |
|
| 105 |
|
| 106 |
$ cat >> .hg/hgrc <<EOF |
| 107 |
> [experimental] |
| 108 |
> update.atomic-file = true |
| 109 |
> EOF |
| 110 |
|
| 111 |
$ hg update -C -r 0 -q |
| 112 |
$ hg update -r 1 --config extensions.showwrites=.hg/showwrites.py 2>&1 | grep "a1'.*wb" |
| 113 |
('vfs open', ('a1', 'wb'), [('atomictemp', True), ('backgroundclose', True)]) |
| 114 |
$ hg st -A --rev 1 |
| 115 |
C a1 |
| 116 |
C a2 |
| 117 |
C b1 |
| 118 |
C b2 |
| 119 |
C d |
| 120 |
C ro |
| 121 |
|
| 122 |
Check the file permission after update |
| 123 |
$ "$PYTHON" $TESTTMP/show_mode.py * |
| 124 |
a1:0644 |
| 125 |
a2:0755 |
| 126 |
b1:0644 |
| 127 |
b2:0755 |
| 128 |
d:0644 |
| 129 |
ro:0644 |
| 130 |
|
| 131 |
Manually reset the mode of the read-only file |
| 132 |
|
| 133 |
$ chmod a-w ro |
| 134 |
|
| 135 |
$ "$PYTHON" $TESTTMP/show_mode.py ro |
| 136 |
ro:0444 |
| 137 |
|
| 138 |
Now the file is present, try to update and check the permissions of the file |
| 139 |
|
| 140 |
$ hg update -r 2 --traceback |
| 141 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 142 |
|
| 143 |
$ "$PYTHON" $TESTTMP/show_mode.py ro |
| 144 |
ro:0644 |
| 145 |
|
| 146 |
# The behavior is the same as without atomic update |