MCPcopy Create free account
hub / github.com/catboost/catboost / RunSymLinkTest

Function RunSymLinkTest

util/system/fs_ut.cpp:192–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190}
191
192static void RunSymLinkTest(TString fileLocalName, TString symLinkName) {
193 // if previous running was failed
194 TFsPath subDir = "tempsubdir";
195 TFsPath srcFile = subDir / fileLocalName;
196
197 TFsPath subsubDir1 = subDir / "dir1";
198 TFsPath subsubDir2 = subDir / "dir2";
199
200 TFsPath linkD1 = "symlinkdir";
201 TFsPath linkD2 = subsubDir1 / "linkd2";
202 TFsPath dangling = subsubDir1 / "dangling";
203
204 NFs::Remove(srcFile);
205 NFs::Remove(symLinkName);
206 NFs::Remove(linkD2);
207 NFs::Remove(dangling);
208 NFs::Remove(subsubDir1);
209 NFs::Remove(subsubDir2);
210 NFs::Remove(subDir);
211 NFs::Remove(linkD1);
212
213 NFs::MakeDirectory(subDir);
214 NFs::MakeDirectory(subsubDir1, NFs::FP_NONSECRET_FILE);
215 NFs::MakeDirectory(subsubDir2, NFs::FP_SECRET_FILE);
216 {
217 TFile file(srcFile, CreateNew | WrOnly);
218 file.Write("1234567", 7);
219 }
220 UNIT_ASSERT(NFs::SymLink(subDir, linkD1));
221 UNIT_ASSERT(NFs::SymLink("../dir2", linkD2));
222 UNIT_ASSERT(NFs::SymLink("../dir3", dangling));
223 UNIT_ASSERT_STRINGS_EQUAL(NFs::ReadLink(linkD2), TString("..") + LOCSLASH_S "dir2");
224 UNIT_ASSERT_STRINGS_EQUAL(NFs::ReadLink(dangling), TString("..") + LOCSLASH_S "dir3");
225 {
226 TFile file(linkD1 / fileLocalName, OpenExisting | RdOnly);
227 UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 7);
228 }
229 UNIT_ASSERT(NFs::SymLink(srcFile, symLinkName));
230 {
231 TFile file(symLinkName, OpenExisting | RdOnly);
232 UNIT_ASSERT_VALUES_EQUAL(file.GetLength(), 7);
233 }
234 {
235 TFileStat fs(linkD1);
236 UNIT_ASSERT(!fs.IsFile());
237 UNIT_ASSERT(fs.IsDir());
238 UNIT_ASSERT(!fs.IsSymlink());
239 }
240 {
241 TFileStat fs(linkD1, true);
242 UNIT_ASSERT(!fs.IsFile());
243 // UNIT_ASSERT(fs.IsDir()); // failed on unix
244 UNIT_ASSERT(fs.IsSymlink());
245 }
246 {
247 TFileStat fs(symLinkName);
248 UNIT_ASSERT(fs.IsFile());
249 UNIT_ASSERT(!fs.IsDir());

Callers 1

TestSymlinkMethod · 0.85

Calls 6

MakeDirectoryFunction · 0.85
IsDirMethod · 0.80
WriteMethod · 0.45
GetLengthMethod · 0.45
IsFileMethod · 0.45
IsSymlinkMethod · 0.45

Tested by 1

TestSymlinkMethod · 0.68