https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112016-11-08T06:13:21ZRuby Issue Tracking SystemRuby master - Bug #12551: Exception accessing file with long path on windowshttps://bugs.ruby-lang.org/issues/12551?journal_id=614002016-11-08T06:13:21Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>FYI, the JRuby issue is waiting on a decision from MRI about how to handle this.</p> Ruby master - Bug #12551: Exception accessing file with long path on windowshttps://bugs.ruby-lang.org/issues/12551?journal_id=621532016-12-21T06:04:13Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li></ul> Ruby master - Bug #12551: Exception accessing file with long path on windowshttps://bugs.ruby-lang.org/issues/12551?journal_id=621662016-12-21T07:38:21Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul></ul><p>Sorry for late reply.</p>
<p>It's too difficult to get rid of the limitation of <code>MAX_PATH</code>,<br>
because many OS API and system functions in C runtime depend on it.</p>
<p>OS API can handle long path with <code>\\?\</code> prefix, but when using this prefix,<br>
the rest must be an absolute path.<br>
Ruby cannot guarantee that a path passed by a user is an absolute path,<br>
so we cannot use this trick at all times.</p> Ruby master - Bug #12551: Exception accessing file with long path on windowshttps://bugs.ruby-lang.org/issues/12551?journal_id=712162018-03-26T05:26:21Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-1 status-5 priority-4 priority-default closed" href="/issues/14631">Bug #14631</a>: Add support for long paths in Windows 10 when support is enabled in the OS</i> added</li></ul> Ruby master - Bug #12551: Exception accessing file with long path on windowshttps://bugs.ruby-lang.org/issues/12551?journal_id=712202018-03-26T11:30:09ZpreetpalS (Preetpal Sohal)preetpal.sohal@gmail.com
<ul></ul><p>usa (Usaku NAKAMURA) wrote:</p>
<blockquote>
<p>It's too difficult to get rid of the limitation of <code>MAX_PATH</code>,<br>
because many OS API and system functions in C runtime depend on it.</p>
<p>OS API can handle long path with <code>\\?\</code> prefix, but when using this prefix,<br>
the rest must be an absolute path.<br>
Ruby cannot guarantee that a path passed by a user is an absolute path,<br>
so we cannot use this trick at all times.</p>
</blockquote>
<p>Python 3.6.2 (64 bits) is able to handle really long paths even when supplied relative paths. I'm not sure how Python is able to do this but its approach might be relevant to solving this issue. Also note that the MAX_PATH limitation was removed from common Win32 file and directory functions starting with Windows 10, Version 1607 (reference: <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath" class="external">https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath</a>).</p>
<pre><code class="python syntaxhl" data-language="python"><span class="kn">import</span> <span class="n">os</span>
<span class="n">i</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">pathToCreate</span> <span class="o">=</span> <span class="sh">"</span><span class="s">python_long_relative_path_stress_test</span><span class="se">\\</span><span class="sh">"</span> <span class="o">+</span> <span class="nf">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="k">while</span> <span class="n">i</span> <span class="o"><</span> <span class="mi">1000</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">i</span> <span class="o">=</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span>
<span class="n">pathToCreate</span> <span class="o">=</span> <span class="n">pathToCreate</span> <span class="o">+</span> <span class="sh">"</span><span class="se">\\</span><span class="sh">"</span> <span class="o">+</span> <span class="nf">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="n">os</span><span class="p">.</span><span class="nf">makedirs</span><span class="p">(</span><span class="n">pathToCreate</span><span class="p">)</span>
<span class="k">except</span><span class="p">:</span>
<span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">Failed to create folder:</span><span class="sh">"</span><span class="p">)</span>
<span class="nf">print</span><span class="p">(</span><span class="nf">len</span><span class="p">(</span><span class="n">os</span><span class="p">.</span><span class="n">path</span><span class="p">.</span><span class="nf">abspath</span><span class="p">(</span><span class="n">pathToCreate</span><span class="p">)))</span>
<span class="nf">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">Could create path of size (using relative paths):</span><span class="sh">"</span><span class="p">)</span>
<span class="nf">print</span><span class="p">(</span><span class="nf">len</span><span class="p">(</span><span class="n">os</span><span class="p">.</span><span class="n">path</span><span class="p">.</span><span class="nf">abspath</span><span class="p">(</span><span class="n">pathToCreate</span><span class="p">)))</span>
</code></pre> Ruby master - Bug #12551: Exception accessing file with long path on windowshttps://bugs.ruby-lang.org/issues/12551?journal_id=712292018-03-26T20:18:29Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I guess if python can do it, ruby will support it as well eventually. :-)</p>
<p>I wish I could help more but my C knowledge is so limited compared<br>
to my knowledge in ruby (and I use linix almost all of the time<br>
rather than windows).</p> Ruby master - Bug #12551: Exception accessing file with long path on windowshttps://bugs.ruby-lang.org/issues/12551?journal_id=846742020-03-16T08:10:36Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Open</i></li><li><strong>Assignee</strong> deleted (<del><i>usa (Usaku NAKAMURA)</i></del>)</li></ul><p>As Python can do it, we know it is theoretically possible. But the priority is low for us, core developers. If someone sends us a pull-request, we'd be happy to review.</p>
<p>Matz.</p> Ruby master - Bug #12551: Exception accessing file with long path on windowshttps://bugs.ruby-lang.org/issues/12551?journal_id=919762021-05-14T20:03:46Zgabuscus (Gabriel Nagy)
<ul></ul><p>Hello,</p>
<p>I managed to compile Ruby with Visual C++ and long paths support by using an application manifest. I validated some basic things like executing a script from a really long path, and creating a directory with path over 255 characters.</p>
<p>This is the code, which works, but I'm hardcoding stuff since I don't know where would be the best place to put it: <a href="https://github.com/GabrielNagy/ruby/commit/eb785c9a567ce058b7e2f16d3a1f53014f245687" class="external">https://github.com/GabrielNagy/ruby/commit/eb785c9a567ce058b7e2f16d3a1f53014f245687</a></p>
<p>I'd appreciate if someone could point me to how I could implement this in a cleaner way.</p>
<p>Thanks!</p> Ruby master - Bug #12551: Exception accessing file with long path on windowshttps://bugs.ruby-lang.org/issues/12551?journal_id=919792021-05-15T08:18:36Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Thank you for the input.<br>
It seems different from this document a little:<br>
<a href="https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd#enable-long-paths-in-windows-10-version-1607-and-later" class="external">https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd#enable-long-paths-in-windows-10-version-1607-and-later</a><br>
Is it convertible?</p> Ruby master - Bug #12551: Exception accessing file with long path on windowshttps://bugs.ruby-lang.org/issues/12551?journal_id=919802021-05-15T09:43:13Zgabuscus (Gabriel Nagy)
<ul></ul><p>I changed it to match the example from Microsoft:</p>
<pre><code class="xml syntaxhl" data-language="xml"><span class="cp"><?xml version="1.0" encoding="utf-8" standalone="yes"?></span>
<span class="nt"><assembly</span> <span class="na">manifestVersion=</span><span class="s">"1.0"</span> <span class="na">xmlns=</span><span class="s">"urn:schemas-microsoft-com:asm.v1"</span> <span class="na">xmlns:asmv3=</span><span class="s">"urn:schemas-microsoft-com:asm.v3"</span><span class="nt">></span>
<span class="nt"><application</span> <span class="na">xmlns=</span><span class="s">"urn:schemas-microsoft-com:asm.v3"</span><span class="nt">></span>
<span class="nt"><windowsSettings</span> <span class="na">xmlns:ws2=</span><span class="s">"http://schemas.microsoft.com/SMI/2016/WindowsSettings"</span><span class="nt">></span>
<span class="nt"><ws2:longPathAware></span>true<span class="nt"></ws2:longPathAware></span>
<span class="nt"></windowsSettings></span>
<span class="nt"></application></span>
<span class="nt"></assembly></span>
</code></pre>
<p>The <code>assembly</code> tag is required as per <a href="https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests" class="external">https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests</a></p> Ruby master - Bug #12551: Exception accessing file with long path on windowshttps://bugs.ruby-lang.org/issues/12551?journal_id=919812021-05-15T11:38:52Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Does this work?<br>
<a href="https://github.com/ruby/ruby/compare/master...nobu:bug/12551-win32-long-path" class="external">https://github.com/ruby/ruby/compare/master...nobu:bug/12551-win32-long-path</a></p> Ruby master - Bug #12551: Exception accessing file with long path on windowshttps://bugs.ruby-lang.org/issues/12551?journal_id=919832021-05-15T21:00:12Zgabuscus (Gabriel Nagy)
<ul></ul><p>Almost! :D Thank you for the makefile improvements.</p>
<p>This took me way longer than expected but I finally have it working: <a href="https://github.com/ruby/ruby/pull/4505" class="external">https://github.com/ruby/ruby/pull/4505</a></p> Ruby master - Bug #12551: Exception accessing file with long path on windowshttps://bugs.ruby-lang.org/issues/12551?journal_id=919872021-05-16T23:33:44Zgabuscus (Gabriel Nagy)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="[Win32] long path name support [Bug #12551] Implement long path support on Windows by applying M..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/229cb0fcdb7957b19d7042b000d803ae58cc6593">git|229cb0fcdb7957b19d7042b000d803ae58cc6593</a>.</p>
<hr>
<p>[Win32] long path name support [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Exception accessing file with long path on windows (Closed)" href="https://bugs.ruby-lang.org/issues/12551">#12551</a>]</p>
<p>Implement long path support on Windows by applying Microsoft's<br>
recommended application manifest.</p>
<p>To make this work on both Visual C++ and MinGW, include the manifest as<br>
a resource when generating the resource files. This way it will be<br>
embedded into the executables generated by both compilers.</p>
<p>It's important for the manifest resource to have ID 1, otherwise GCC<br>
will embed a default manifest.</p>
<p>Note that in addition to this, the user needs to have <a href="https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd#enable-long-paths-in-windows-10-version-1607-and-later" class="external">long paths enabled</a><br>
either by modifying the registry or by enabling a group policy.</p>
<p>Co-authored-by: Nobuyoshi Nakada <a href="mailto:nobu@ruby-lang.org" class="email">nobu@ruby-lang.org</a></p>