D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17167 - dmd fails to write to file or create directory with more than 248 characters in the path
Summary: dmd fails to write to file or create directory with more than 248 characters ...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Windows
: P2 blocker
Assignee: No Owner
URL:
Keywords:
: 17888 (view as issue list)
Depends on:
Blocks:
 
Reported: 2017-02-09 17:58 UTC by Atila Neves
Modified: 2022-06-09 14:01 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Atila Neves 2017-02-09 17:58:33 UTC
I saw this while running dub on Windows:

Error: Error writing file '..\..\..\..\..\..\AppData\Roaming\dub\packages\taggedalgebraic-0.10.5\taggedalgebraic\.dub\build\library-debug-windows-x86-dmd_2073-20BD164B4B4CA7B99E316352127B8128\taggedalgebraic.lib'

If I move the source directory up one directory this stops happening (i.e., dmd would write the output library to '..\..\..\..\..\AppData\Roaming\dub\packages\taggedalgebraic-0.10.5\taggedalgebraic\.dub\build\library-debug-windows-x86-dmd_2073-20BD164B4B4CA7B99E316352127B8128\taggedalgebraic.lib' instead, and successfully)
Comment 1 Atila Neves 2017-11-01 10:09:48 UTC
*** Issue 17888 has been marked as a duplicate of this issue. ***
Comment 2 Atila Neves 2017-11-01 11:26:36 UTC
After some investigation, it seems that dub specifying relative paths makes it more likely to pass the 248 character limit, since Windows first appends the current absolute path to the relative one. This is a known Windows limitation up until an opt-in in Windows 10 to make the problem go away, and otherwise has to be dealt with by calling the Unicode-aware Win32 file APIs.
Comment 3 github-bugzilla 2017-11-15 03:53:59 UTC
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/34f6dedb18fd3d9e6aacac8469f6515da2e77928
Fix issue 17167 - handle long filepaths on Windows

https://github.com/dlang/dmd/commit/24ab619f310eed641a60cad492460a0af4e7f0cf
Merge pull request #7299 from kaleidicassociates/fix_issue_17167

Fix issue 17167 - handle long filepaths on Windows
merged-on-behalf-of: Walter Bright <WalterBright@users.noreply.github.com>
Comment 4 github-bugzilla 2017-12-18 22:57:03 UTC
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/34f6dedb18fd3d9e6aacac8469f6515da2e77928
Fix issue 17167 - handle long filepaths on Windows

https://github.com/dlang/dmd/commit/24ab619f310eed641a60cad492460a0af4e7f0cf
Merge pull request #7299 from kaleidicassociates/fix_issue_17167
Comment 5 github-bugzilla 2017-12-21 18:53:46 UTC
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/c22616ae6ea9c6832d4c261bc957149c2b265a98
Temporarily disable test for issue 17167 on CircleCi

https://github.com/dlang/dmd/commit/9b45aa736fd08eed3d20c41c5014f7ff68833bc0
Merge pull request #7486 from wilzbach/circleci-fix

Temporarily disable test for issue 17167 on CircleCi
merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
Comment 6 Vino 2017-12-22 15:56:59 UTC
While trying to find the size of a file which was residing in a path more than 300 character length we were getting the error : The system cannot find the path nor the file exist , so does this fix resolve even this issue. In the below example there are 50-60 sub folders.


auto SdFiles = Array!ulong(dirEntries("C:\\Test", SpanMode.depth).map!(a => a.size)).

From,
Vino.B
Comment 7 Atila Neves 2017-12-22 17:24:22 UTC
@Vino Probably. Try out with dmd at master and see. If not, please file a new issue.
Comment 8 Vino 2018-04-09 04:01:52 UTC
Hi All,

  As per the issue id 17167 it states that this issue is resolved, but the issue still persist as it tested with DMD32 D Compiler v2.079.1-beta.1 on Windows 2008 R2. so as a temporary solution we have used the UNC path as below

Original Path : C:\Test\1\2\3\4\5\6.............\
UNC Path : \\?\C:\Test\1\2\3\4\5\6.............\

Issue : The appending of UNC path is consuming time and memory as it appends to each file's and folders inside the file system.

Note: The file system is a windows share from Netapp.

May i know when will this be fixed.

From,
Vino.B
Comment 9 Atila Neves 2018-04-09 13:19:49 UTC
Have you checked this page?

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

I filed this bug because dub was using relative paths and ended up trying to link to ..\..\..\..\..\Users\%USERNAME%\AppData\Roaming\dub\packages\package-name-version\package-name.

Before the fix, if the dub path with several .. was too large (which happened often), nothing would work. Now, it does.

It's possible that passing in an absolute path is different. I would still say that it's a new bug.
Comment 10 Dlang Bot 2022-03-17 07:31:43 UTC
@Geod24 updated dlang/dmd pull request #13828 "Simplify `Module.read` and its interaction with `FileManager`" mentioning this issue:

- Windows: Make FileName.exists correctly work with long path
  
  While attempting to refactor Module.read not to call 'File.read' twice,
  test17167 started to fail. The only possible difference was that
  the first File.read call was conditional on FileName.exists succeeding,
  while the second call was inconditional.
  After a bit of research, it turns out that the fix for issue 17167
  was apparently missing one key detail (the prefix) to enable long path.
  This was not visible at the time because the fix for File.read was complete,
  and so the second attempt would succeed, hiding the issue.

https://github.com/dlang/dmd/pull/13828
Comment 11 Dlang Bot 2022-03-17 11:18:17 UTC
dlang/dmd pull request #13828 "Simplify `Module.read` and its interaction with `FileManager`" was merged into master:

- 8f2a7b139fa06fe3c36c0598ddc114c331d581f6 by Geod24:
  Windows: Make FileName.exists correctly work with long path
  
  While attempting to refactor Module.read not to call 'File.read' twice,
  test17167 started to fail. The only possible difference was that
  the first File.read call was conditional on FileName.exists succeeding,
  while the second call was inconditional.
  
  After a bit of research, it turns out that the fix for issue 17167
  was apparently missing one key detail (the prefix) to enable long path.
  This was not visible at the time because the fix for File.read was complete,
  and so the second attempt would succeed, hiding the issue.
  
  This brings into question the correctness / need for toWStringzThen,
  as it's mostly used for long path, and is still being used in cannonicalName.

https://github.com/dlang/dmd/pull/13828