Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Really long windows dirs #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/hg-utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ suppressHgWarnings = [
]

class Repository

isWindows = process.platform == 'win32'
windowsMaxPathLength = 260
username: null
password: null

Expand Down Expand Up @@ -291,7 +292,10 @@ class Repository
if err
reject err
if stderr?.length > 0
reject stderr
if isWindows and stderr.length > windowsMaxPathLength
resolve(stdout)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the error thrown in this case? The result still comes from the stdout? Just files with path < 260?

If I'm right, maybe we need to put a comment here specifying that the error is probably something related to a big file path.

Whats leads us to: is there anything in the error message that could specify it better than its length being greater than 260 chars?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it ain't pretty.

The problem is that the error is just a string
/path/that/is/long could not find file or somesuch

The problem is that there is no error code or somesuch and windows error message could be localized, so I can't match the string.

Given that windows-paths can also contain spaces I'm not quite sure how to reliably recognize the situation.

The only case I could think of is deliberately trying to cause the error at startup with a well-known directory and saving 'the rest of the string'. But that sounds like a little bit too much work for such a small edge-case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very much open to suggestions though!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 'could not find file' in stderr a better solution than stderr.length > 260?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that works since the error message could be localized, so if I had the dutch language pack enabled it would be 'bestand kon niet gevonden worden' or somesuch.

...there's got to be a better way though.

else
reject new Error(stderr)
resolve stdout

handleHgError: (error) ->
Expand Down
31 changes: 31 additions & 0 deletions test/long_windows_paths.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'coffee-script/register'
require './fakeWindow'
HgRepository = require '../lib/hg-repository'
TestRepository = require './testRepository'
assert = require('chai').assert
path = require 'path'
exec = require('child_process').execSync

isWindows = process.platform == 'win32'
unless isWindows
return

describe 'In a repository with a really long path', ->
testRepo = new TestRepository path.parse(__filename).name
repo = null
before ->
testRepo.init()

beforeEach ->
repo = new HgRepository (testRepo.fullPath())

it 'should still return isPathIgnored true', ->
ignored_file = path.join testRepo.fullPath(), 'ignored_file'
repo.refreshStatus().then ->
assert.equal(repo.isPathIgnored(ignored_file), true)

after ->
command = 'dir \'' + testRepo.fullPath() + '\\subDir*\' | rename-item -NewName a'
command = 'powershell -command "' + command + '"'
exec command
testRepo.destroy()
18 changes: 18 additions & 0 deletions test/long_windows_paths.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
hg init $args[0]
set-location $args[0]

Set-Content -Path ".hgignore" -Value @"
syntax:glob
ignored_file
"@
hg add ".hgignore"

new-item -type File "ignored_file"
new-item -type Directory "subdir"
new-item -type File "subdir/some_file"

$subDir = get-item "subdir"
$path = $subDir.FullName
$path = $path.PadRight(259, "A")

rename-item "subdir" (Split-Path $path -Leaf)