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

Sublime hangs when opening relative path #27

Open
thorstenkampe opened this issue Jan 18, 2016 · 8 comments
Open

Sublime hangs when opening relative path #27

thorstenkampe opened this issue Jan 18, 2016 · 8 comments

Comments

@thorstenkampe
Copy link

Sublime Text 3 (Build 3095) hangs when opening a file with a relative path (like \Documents\text.txt) on Windows 10. Absolute paths like C:\Documents\text.txt work fine.

iOpener v 2.0.1

@mattst
Copy link
Collaborator

mattst commented Jan 18, 2016

Thanks for the bug report.

Firstly I'm not a Windows user, but I do have WinXP 32 which I run in VirtualBox (since XP is now ancient it's not the best situation for testing iOpener with Windows).

I wasn't aware that a Windows path could begin with a \ at all. The Wikipedia Path page says that a path beginning with a \ is relative to the current directory. I suspect that paths beginning with a \ are intended for use only within the Command Shell; there is certainly no concept of a current directory in the context of iOpener.

When I entered entered a single \ in the iOpener input and hit tab twice to get completions, the directory contents of C:\ was shown and I was able to open a file - BUT the file was empty (it did not show the text I'd placed in the file). I had used iOpener to open \Temp\file.txt but somehow this had been transformed to T:emp\file.txt which was shown in the Sublime Text window's command bar, the same garbled path was shown in the error message which Sublime Text displayed when I tried to save the empty file; this was not a surprise as clearly T:emp\file.txt is not a valid path.

I can definitely confirm that it was NOT iOpener which transformed \Temp\file.txt to T:emp\file.txt, that must have been done by Sublime Text itself.

My conclusion is that iOpener allows paths to begin with a \ on Windows, and will treat them as C:\ for completions, but that Sublime Text will not accept these paths. On WinXP 32 this just results in an error while on Win10 it causes Sublime Text to hang (at least on whatever version of Win10 you're using).

From now on, I suggest you only use absolute paths and the home ~\ notation with iOpener.

@ross - Python accepts \Temp\file.txt as a valid path on Windows, when expanduser() is given that text it returns the same text, split(), isdir(), etc. all accept it as well. Either it is accepted because it's technically a valid Windows path or because it is a Linux/UNIX path and the Python os.path module is less platform aware than I would have thought. I suggest that sublime.platform() is used to check the platform and to disallow paths beginning with \ on Windows. I'll be happy to make the changes necessary. I've made some more improvements and minor bug fixes in my dev-mattst branch, I've been tinkering from time to time during Jan, so don't merge my pull request yet - I've got changes to add and will push them when I've had time to finish them.

Hope this helps.

@ross
Copy link

ross commented Jan 18, 2016

@ross - Python accepts \

I don't believe I'm the Ross you're looking for :-)

@mattst
Copy link
Collaborator

mattst commented Jan 18, 2016

Nope, that must have been a bit weird for you. Look who owns iOpener at the top of the page.

@thorstenkampe
Copy link
Author

For the record: paths starting with a \ are always absolute paths: they start from the root of the drive. Windows has multiple current directories. One for each drive. C:tmp refers to the tmp directory in your current working directory on the C: drive.

@ross
Copy link

ross commented Jan 18, 2016

Nope, that must have been a bit weird for you. Look who owns iOpener at the top of the page.

No worries. It happens at least a couple of times a month. The downside of owning @ross.

@thorstenkampe
Copy link
Author

Using Alt-F, O (Open File) in Sublime with an absolute path without drive results in Sublime opening the file (no surprise here)

@mattst
Copy link
Collaborator

mattst commented Jan 18, 2016

@ross - Ohh, I see. Many apologies Ross, I didn't realize that @Ross would actually notify someone, I just used that so that rosshemsley would see that bit was directed at him when he reads the issue and stupidly I thought you must have just happened to be reading the page. And you're GitHub staff too, oops, great site, etc., BTW I like your Puzzle Solver.

@mattst
Copy link
Collaborator

mattst commented Jan 18, 2016

@thorstenkampe - Thanks.

So I guess I misunderstood the Wikipedia page, a path beginning with a \ is relative to the current drive and not the current directory (the %CD% threw me).

Using Alt-F, O (Open File) in Sublime with an absolute path without
drive results in Sublime opening the file (no surprise here)

That works for me too.

I'm afraid that it makes no difference that paths beginning with \ work using the regular ST open dialog box. I'd guess that works because the open dialog box has a 'current drive', that being the drive of whatever directory is being displayed. Windows is then smart enough to translate something like \Temp\file.txt into C:\Temp\file.txt which it then gives to ST - it's Windows that handles these kinds of paths and not ST.

For a ST plugin to open a file in a ST window the open_file(path) method of the API is used. Earlier I tried the code below, and ended up with the garbled file path T:emp\file.txt, as previously described.

sublime.active_window().open_file("\Temp\file.txt")

For the plugin to open the file it would need to select a drive and create an absolute path for the one beginning with the \. Easy enough except for the fact that there is no concept of a current drive in the context of iOpener. iOpener would have to guess which drive to use: should it use the drive of the currently open file, of the last file opened, or maybe of the drive which holds the ST executable (the location of which is what you get if you request the current working directory); of course there may be no open files at all. It would not be good software design to guess which drive the user wants; better to require an absolute path or one relative to the home directory and to prevent users from submitting a path beginning with a \ as it can cause ST to hang (which is very helpful information, thanks again for it).

Hope this clarifies things.

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

No branches or pull requests

3 participants