| 148 | } |
| 149 | |
| 150 | static void RunHardlinkTest(const TFsPath& src, const TFsPath& dst) { |
| 151 | NFs::Remove(src); |
| 152 | NFs::Remove(dst); |
| 153 | |
| 154 | { |
| 155 | TFile file(src, CreateNew | WrOnly); |
| 156 | file.Write("123", 3); |
| 157 | } |
| 158 | |
| 159 | UNIT_ASSERT(NFs::HardLink(src, dst)); |
| 160 | |
| 161 | { |
| 162 | TFile file(dst, OpenExisting | RdOnly); |
| 163 | UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 3); |
| 164 | } |
| 165 | { |
| 166 | TFile file(src, OpenExisting | WrOnly); |
| 167 | file.Write("1234", 4); |
| 168 | } |
| 169 | { |
| 170 | TFile file(dst, OpenExisting | RdOnly); |
| 171 | UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 4); |
| 172 | } |
| 173 | { |
| 174 | TFile file(dst, OpenExisting | WrOnly); |
| 175 | file.Write("12345", 5); |
| 176 | } |
| 177 | |
| 178 | { |
| 179 | TFile file(src, OpenExisting | RdOnly); |
| 180 | UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 5); |
| 181 | } |
| 182 | |
| 183 | UNIT_ASSERT(NFs::Remove(dst)); |
| 184 | UNIT_ASSERT(NFs::Remove(src)); |
| 185 | } |
| 186 | |
| 187 | void TFsTest::TestHardlink() { |
| 188 | RunHardlinkTest("tempfile", "hardlinkfile"); |