Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Support long paths #117

Closed
wants to merge 1 commit into from
Closed

Support long paths #117

wants to merge 1 commit into from

Conversation

kblees
Copy link

@kblees kblees commented Jan 18, 2014

Hi all,

here's my take on the long paths issue, carrying on ideas from #85, #86, #110 and #113 discussions.

Unfortunately, I won't have the time to test this with long paths (the test suite passes). So I'd like to ask interested parties (@nitram509, @vangdfang) to give it a try and report back if it fixes your issues.

Have fun,
Karsten

Windows paths are typically limited to MAX_PATH = 260 characters, even
though the underlying NTFS file system supports paths up to 32,767 chars.
This limitation is also evident in Windows Explorer, cmd.exe and many
other applications (including IDEs).

Particularly annoying is that most Windows APIs return bogus error codes
if a relative path only barely exceeds MAX_PATH in conjunction with the
current directory, e.g. ERROR_PATH_NOT_FOUND / ENOENT instead of the
infinitely more helpful ERROR_FILENAME_EXCED_RANGE / ENAMETOOLONG.

Many Windows wide char APIs support longer than MAX_PATH paths through the
file namespace prefix ('\\?\' or '\\?\UNC\') followed by an absolute path.
Notable exceptions include functions dealing with executables and the
current directory (CreateProcess, LoadLibrary, Get/SetCurrentDirectory) as
well as the entire shell API (ShellExecute, SHGetSpecialFolderPath...).

Introduce a handle_long_path function to check the length of a specified
path properly (and fail with ENAMETOOLONG), and to optionally expand long
paths using the '\\?\' file namespace prefix. Short paths will not be
modified, so we don't need to worry about device names (NUL, CON, AUX).

Contrary to MSDN docs, the GetFullPathNameW function doesn't seem to be
limited to MAX_PATH (at least not on Win7), so we can use it to do the
heavy lifting of the conversion (translate '/' to '\', eliminate '.' and
'..', and make an absolute path).

Add long path error checking to xutftowcs_path for APIs with hard MAX_PATH
limit.

Add a new MAX_LONG_PATH constant and xutftowcs_long_path function for APIs
that support long paths.

While improved error checking is always active, long paths support must be
explicitly enabled via 'core.longpaths' option. This is to prevent end
users to shoot themselves in the foot by checking out files that Windows
Explorer, cmd/bash or their favorite IDE cannot handle.

Thanks-to: Martin W. Kirst <maki@bitkings.de>
Thanks-to: Doug Kelly <dougk.ff7@gmail.com>
Signed-off-by: Karsten Blees <blees@dcon.de>
@buildhive
Copy link

MSysGit - the development behind Git for Windows » git #170 FAILURE
Looks like there's a problem with this pull request
(what's this?)

@kblees
Copy link
Author

kblees commented Jan 18, 2014

Note: Buildhive problem is because this patch cannot be merged (I started fresh from before the #86 merge).

@dscho
Copy link
Member

dscho commented Feb 7, 2014

I had a quick look at it two weeks ago (and no time to follow up with it) and have two notes:

  • You could just have rebased your branch on top of Revert #86 and #111 #114 (but I will redo that anyway, to make it easier to remember to undo the merges in a later merging rebase).
  • @vangdfang 's test does not pass (it actually does not pass here with the magic path length at all because the magic path length has to be longer in my setup). The reason is that your changes do not touch PATH_MAX and as a consequence all Git commands including git clone cannot handle long paths at all.

That's where things got stuck for me. I should find the time to clean my local patches up a little and push them, but not today...

@kblees kblees mentioned this pull request Feb 8, 2014
@kblees
Copy link
Author

kblees commented Feb 8, 2014

@dscho the problem wasn't PATH_MAX after all, but thanks for looking into it anyway

I'm closing this in favor of #122

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants