diff options
author | kikht <kikht@yandex-team.ru> | 2022-02-17 22:22:02 +0300 |
---|---|---|
committer | kikht <kikht@yandex-team.ru> | 2022-02-17 22:22:02 +0300 |
commit | a4e5577781d9f1162779286558a90252430f6200 (patch) | |
tree | 2c85c7eb414fe138e451463bdb0d5fe89419a916 /util/generic/yexception.cpp | |
parent | af4af5b490ed7283af1288054d4581b1dbc64660 (diff) | |
download | ydb-a4e5577781d9f1162779286558a90252430f6200.tar.gz |
[util] fix fstat for archive directories on windows
Currently TFileStat has a bunch of problems on Windows:
1. Mode computation ORs different types, but file attributes it checks are not mutually exclusive. E.g. it is possible for directory to have both `FILE_ATTRIBUTE_DIRECTORY` and `FILE_ATTRIBUTE_ARCHIVE`, but it will currently lead to invalid `_S_IFDIR | _S_IFREG` mode.
2. Any file with `FILE_ATTRIBUTE_REPARSE_POINT` flag is considered to be symlink. But there are many other types of reparse points even user-defined ones. For more info see https://docs.microsoft.com/en-us/windows/win32/fileio/reparse-point-tags
To fix all this we do the following:
1. Add `ReparseTag` field to `TSystemFStat` and fill it for reparse points in `GetStatByHandle`.
2. Refactor `GetWinFileType` out of `GetFileMode` to ensure that we always select only single `S_IFMT` value.
3. Pass reparse tag value into `GetWinFileType` and select `S_IFLNK` only for `IO_REPARSE_TAG_SYMLINK` and `IO_REPARSE_TAG_MOUNT_POINT` tags. The latter one is a bit strange, but this behaviour is aligned with current implementation of `WinReadLink`.
4. Factor `ReadReparsePoint` out of `WinReadLink`. This function uses `DeviceIoControl` to read reparse point data into structures copied from WDK.
5. Add `WinReadReparseTag` that uses `ReadReparsePoint` to extract reparse point tag. We use this approach instead of MSDN-recommended `FindFirstFile` because latter requires file path, but we have file handle at this point. AFAIK golang and python use similar approach for this.
6. Add test for archived directory case.
7. Make symlink nofollow tests run only when symlink creation is possible for current user.
Discovered in https://st.yandex-team.ru/ARC-3931
ref:4f6735817b9f85f3351a1021a56dd7eb4606bd65
Diffstat (limited to 'util/generic/yexception.cpp')
0 files changed, 0 insertions, 0 deletions