twinstar6980 / Twinning

https://github.com/twinstar6980/Twinning.Documentation
GNU General Public License v3.0
58 stars 12 forks source link

Bug: reading path with more than 260 characters #26

Closed Haruma-VN closed 6 months ago

Haruma-VN commented 7 months ago

I tried to use the Kernel to write the file on my Windows OS (the path have more than 260 characters), below is the script (The directory is already existed, so it is not the bug come from me), I think you should add the prefix "\\?\" for Windows machine: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-wfopen?view=msvc-170

In Kernel/kernel/utility/file_system/file_system.hpp line 157 make this change:

auto file = _wfopen(cast_pointer<WCHAR>(make_null_terminated_string(StringEncoding::utf8_to_utf16(self_cast<BasicString<Character8>>(make_string(Third::fmt::format("\\\\?\\{}", make_regular_path(target).to_string().view()))))).begin()).value, cast_pointer<WCHAR>(make_null_terminated_string(StringEncoding::utf8_to_utf16(self_cast<BasicString<Character8>>(make_string_view(mode)))).begin()).value);

image test.zip

twinstar6980 commented 7 months ago

no error on my device. 400+- chars path: image

Haruma-VN commented 7 months ago

Can it write the file on your system? For me the error

file != nullptr

still occur. When I modify the Kernel it becomes regular.

twinstar6980 commented 7 months ago

On my device, the tool can read/write long path files. Does this problem also occur in shellgui and helper?

Haruma-VN commented 7 months ago

For me they occur in all Shell environment. It seems like this relate to Kernel?

Haruma-VN commented 6 months ago

@twinkles-twinstar when reading it is normal but when write it is not, can you check it?

image

image

Below is the script, note that i write to the same file path.

test.zip

twinstar6980 commented 6 months ago

I tested this script and on my device, the \\?\ prefix has no effect on reading and writing files. It seems that Windows does not allow us to use _wfopen to create files with too long names (although the total length can exceed 260, a single name still cannot be too long). In your screenshot, writing the file failed because 100000... is too long; reading the file succeeded because the end of 100000... was deleted from the file name (I guess you If you create a file through explorer, it will automatically delete the end part of the file name that is too long). If you compare carefully, you can see that the file being read and the file you wish to write are different. As shown in the figure below, even if the \\?\ prefix is used, the file name that is too long is still illegal (Figure 2).

1.suc 2.fai