gmcclure382 / stexbar

Automatically exported from code.google.com/p/stexbar
0 stars 0 forks source link

"Copy paths" doesn't convert path to UNC format #234

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
0. Enable "Copy UNC paths" in Settings
1. Navigate to a mapped network drive (ie. P:\TEMP)
2. Click "Copy Paths"
3. Check the path copied to clipboard

What is the expected output? What do you see instead?
Path should be in UNC format

What version of the product are you using? On what operating system?
Windows XP SP3
StExBar 1.8.2.316
Computer is in corporate network with multiple mapped network shares.
Computer has also VMWare Player installed, some shared folders enabled (this 
might be relevant).
Computer has multiple network interfaces, some of them virtual.

Please provide any additional information below.
If I navigate to the same folder using the UNC path, then the path is copied to 
clipboard correctly in UNC format.

We have another in-house tool with the exact same issue. There we could fix the 
problem by using WNetGetConnection() instead of WNetGetUniversalName(). StExBar 
seems to do the UNC conversion in ConvertToUnc() in ExPaths.cpp.

Python code for workaround (requires win32api module):

import win32wnet, os.path

# Convert path on mapped network drive to UNC notation (from P:\FOO to 
\\server\share\FOO)
def ToUnc(Path):
    retval = Path
    try:
        # Split path to (drive, tail); for example, r"C:\TEMP" would be split to ("C:", "\TEMP")
        drive, tail = os.path.splitdrive(Path)

        # Convert the mapped drive to UNC
        unc_drive = win32wnet.WNetGetConnection(drive)

        retval = unc_drive + tail
    except:
        # WNetGetConnection may fail for non-network paths, but we don't care, just return the unmodified path
        pass
    return retval

print ToUnc(r"P:\PROJ")
#returns \\server\share\PROJ

print ToUnc(r"C:\temp")
#returns C:\temp

Original issue reported on code.google.com by juho.rou...@gmail.com on 19 Nov 2013 at 1:44

GoogleCodeExporter commented 8 years ago
This is how WNetGetUniversalName() fails:

>>> win32wnet.WNetGetUniversalName(r"P:\\PROJ")

Traceback (most recent call last):
  File "<pyshell#39>", line 1, in <module>
    win32wnet.WNetGetUniversalName(r"P:\\PROJ")
error: (1203, 'WNetGetUniversalName (for buffer size)', 'No network provider 
accepted the given network path.')

Original comment by juho.rou...@gmail.com on 19 Nov 2013 at 1:46