| | @@ -9,13 +9,19 @@ namespace Zipelo.Runtime; |
| 9 | 9 | internal sealed class LinuxFolderPublication : PendingFolderPublication |
| 10 | 10 | { |
| 11 | 11 | private readonly SafeFileHandle parent; |
| 12 | +추가: private readonly string parentPath; |
| 13 | +추가: private ulong parentMountId; |
| 12 | 14 | private readonly uint user = GetEffectiveUser(); |
| 13 | 15 | private string parentIdentity = ""; |
| 14 | 16 | private bool unboundCreation; |
| 15 | 17 | internal int? NativeError { get; private set; } |
| 16 | 18 | internal int? CleanupError { get; private set; } |
| 17 | 19 | |
| 18 | | -삭제: internal LinuxFolderPublication(string path) => parent = Open(-100, path, 0x90000, 0, 0x04); |
| 20 | +추가: internal LinuxFolderPublication(string path) |
| 21 | +추가: { |
| 22 | +추가: parentPath = path; |
| 23 | +추가: parent = Open(-100, path, 0x90000, 0, 0x04); |
| 24 | +추가: } |
| 19 | 25 | |
| 20 | 26 | internal override void Initialize() |
| 21 | 27 | { |
| | @@ -33,7 +39,7 @@ internal sealed class LinuxFolderPublication : PendingFolderPublication |
| 33 | 39 | 0x58465342 => "xfs", |
| 34 | 40 | _ => throw new ArchiveException(ArchiveError.OutputUnavailable) |
| 35 | 41 | }; |
| 36 | | -삭제: var before = MountStatus(); |
| 42 | +추가: var before = MountStatus(parent); |
| 37 | 43 | var mountId = BitConverter.ToUInt64(before, 144); |
| 38 | 44 | var device = FormattableString.Invariant($"{BitConverter.ToUInt32(before, 136)}:{BitConverter.ToUInt32(before, 140)}"); |
| 39 | 45 | |
| | @@ -69,18 +75,19 @@ internal sealed class LinuxFolderPublication : PendingFolderPublication |
| 69 | 75 | throw new ArchiveException(ArchiveError.OutputUnavailable); |
| 70 | 76 | } |
| 71 | 77 | } |
| 72 | | -삭제: var after = MountStatus(); |
| 78 | +추가: var after = MountStatus(parent); |
| 73 | 79 | if (matches != 1 || BitConverter.ToUInt64(after, 144) != mountId || |
| 74 | 80 | Identity(before) != Identity(after) || FileSystemMagic(parent) != magic) |
| 75 | 81 | { |
| 76 | 82 | throw new ArchiveException(ArchiveError.OutputUnavailable); |
| 77 | 83 | } |
| 84 | +추가: parentMountId = mountId; |
| 78 | 85 | } |
| 79 | 86 | |
| 80 | | -삭제: private byte[] MountStatus() |
| 87 | +추가: private byte[] MountStatus(SafeFileHandle handle) |
| 81 | 88 | { |
| 82 | 89 | // mountinfo의 기존 mount ID와 대조하므로 UNIQUE 플래그를 요청하지 않음. |
| 83 | | -삭제: var status = Stat(parent, "", 0x1100, 0x17FF); |
| 90 | +추가: var status = Stat(handle, "", 0x1100, 0x17FF); |
| 84 | 91 | if ((BitConverter.ToUInt32(status, 0) & 0x1000) == 0 || BitConverter.ToUInt64(status, 144) == 0) |
| 85 | 92 | { |
| 86 | 93 | throw new ArchiveException(ArchiveError.OutputUnavailable); |
| | @@ -171,6 +178,21 @@ internal sealed class LinuxFolderPublication : PendingFolderPublication |
| 171 | 178 | } |
| 172 | 179 | } |
| 173 | 180 | |
| 181 | +추가: private void RequireParentIdentity(SafeFileHandle selectedParent) |
| 182 | +추가: { |
| 183 | +추가: var pinned = MountStatus(parent); |
| 184 | +추가: var selected = MountStatus(selectedParent); |
| 185 | +추가: if (parentMountId == 0 || |
| 186 | +추가: BitConverter.ToUInt64(pinned, 144) != parentMountId || |
| 187 | +추가: BitConverter.ToUInt64(selected, 144) != parentMountId || |
| 188 | +추가: Identity(pinned) != parentIdentity || Identity(selected) != parentIdentity || |
| 189 | +추가: Inspect(parent, true) != parentIdentity || Inspect(selectedParent, true) != parentIdentity || |
| 190 | +추가: FileSystemMagic(selectedParent) != FileSystemMagic(parent)) |
| 191 | +추가: { |
| 192 | +추가: throw new ArchiveException(ArchiveError.UnsafePath); |
| 193 | +추가: } |
| 194 | +추가: } |
| 195 | +추가: |
| 174 | 196 | internal override void Publish(string leaf, CancellationToken token) |
| 175 | 197 | { |
| 176 | 198 | RequireName(Root); |
| | @@ -180,6 +202,10 @@ internal sealed class LinuxFolderPublication : PendingFolderPublication |
| 180 | 202 | if (Fsync(node.Handle) != 0) { ThrowLast(); } |
| 181 | 203 | } |
| 182 | 204 | token.ThrowIfCancellationRequested(); |
| 205 | +추가: // 원래 경로를 링크 없이 다시 열어 게시 전 교체를 검사함. rename과 원자적이지 않음. |
| 206 | +추가: using var selectedParent = Open(-100, parentPath, 0x90000, 0, 0x04); |
| 207 | +추가: RequireParentIdentity(selectedParent); |
| 208 | +추가: token.ThrowIfCancellationRequested(); |
| 183 | 209 | // RENAME_NOREPLACE가 없는 커널/FS에서는 대체 경로 없이 실패함. |
| 184 | 210 | if (Renameat2(parent, TemporaryName, parent, leaf, 1) != 0) { ThrowLast(); } |
| 185 | 211 | } |