Perforce Public Knowledge Base - Submitting or Syncing Files with Long Path Names
× PRODUCTS SOLUTIONS CUSTOMERS LEARN SUPPORT
Downloads Company Partners Careers Contact Free Trials
Menu Search
Perforce
Reset Search
 

 

Article

Submitting or Syncing Files with Long Path Names

« Go Back

Information

 
Problem

Prior to Perforce release 2015.1:  The Windows 260 character path limit could not be circumvented completely when a long path (longer than 260-character) name file is synced to the Windows client from a non-Windows (i.e. Unix/Linux/Mac) server, and when a path name longer than 260 characters is submitted to a Windows Perforce server from a non-Windows (i.e. Unix/Linux/Mac) client.

NOTES:

Solution

DETAILS

As of Perforce release 2015.2 and later, Windows long file name support now defaults to enabled.  This is equivalent to this tunable setting, "filesys.windows.lfn=1". 
The following setting no longer needs to be configured on clients, "-vfilesys.window.lfn=1".

As of Perforce release 2015.1, the Windows platform can now support filenames longer than 260 characters.  The "filesys.windows.lfn=1" tunable must be set where ever this functionality is required, Client and Server.

For Perforce releases 2014 and earlier, if you are running a Perforce server on a non-Windows operating system and you are using non-Windows clients, there is no path name length limit that you need to worry about. However, you will run into the long path name issue if either the Perforce server or clients (or both server and client) are running a Windows-based operating system.

In the Windows API, the maximum length for a path is MAX_PATH, which is defined as 260 characters. Although the NTFS file system supports paths of 32,000 characters, the majority of Windows APIs accept paths of MAX_PATH (260) or smaller. This pathname limitation results in a Perforce user encountering a problem submitting a file name/path that exceeds MAX_PATH in a Windows environment.

The following example demonstrates the error you get when trying to add or retrieve a file with a name exceeding the MAX_PATH limit:

mkdir: depot/products/cm/testing_these_products/server/my_new_imageserver/20060617_ser
ver_pais_1.0.0.56886/programmingreference/sampleapps/identificationservice/
identificationservice/bin/release/identificationservice.xmlserializers.dll,d: 

The system cannot find the file specified.
or
Proxy could not update its cache.

It might not appear that the errors are related to the Windows API, but the errors are, in fact, a result of exceeding the MAX_PATH limit. This is an example where the Perforce server is non-Windows whereas the client is running a Windows operating system.  Because of the Windows 260-character limit, the client operating system is unable to create a path name longer than 260 characters during sync operation.

If you are running a Windows Perforce server and you have a non-Windows client version 2015.1 or earlier, you will have a problem submitting a file if the path name length is longer than 260 characters.

There are three partial workarounds for the path limit problem when you do a submit and a sync in Perforce:

  • Shorten the directory path using the subst command or the linkd command (This will only work in a case where the path name length slightly exceed the 260-character limit)
  • Prepend \\?\ to the existing file name (This method is unverified and it is known to work according to the Microsoft article noted below)
  • Use P4Eclipse (P4WSAD) plug-in to sync and submit files under Windows (This will not work in the case where you have the Perforce server running on Windows)

Example changing the client root using subst

  1. Create a subst drive

    Map the directory path to a drive name using the subst command on the command line. For example, if your current path is "D:\Documents and Settings\perforce\My Documents\Visual Studio 8\Workspace1\", you can shorten the path by entering the following command:
    subst f: "D:\Documents and Settings\perforce\My Documents\Visual Studio 8\Workspace1\"
    The F: drive becomes a shortened form of the longer path that you specified. Change the command line directory to reflect the new path name:
    C:\>f:
    f:\>
    
  2. Choose your client workspace

    Change your client workspace root to this shorter path. Create or choose a client workspace from P4V, or enter the following command from the command line:
    p4 client <clientname>
    
  3. Change the "Root:" to "Root: F:\" and save the change.
    Root: F:\
  4. Check that the client root is set

    Type p4 client -o to check if the client root is set correctly, or double-click on the workspace name in the Workspaces pane of P4V (View->Workspaces from the GUI menu).
    p4 client -o
    

Issues while syncing

Users switching to P4V from P4Win may run into issues with syncing to Perforce due to the same file length limitation. While the technique above could reduce all the file lengths in the workspace below the path length limitation in Windows, there may still be errors when attempting to sync or submit files from P4V due to the location of the Windows TMP/TEMP directory.
 
The path for the P4V temporary files created during sync is in this format:
{drive letter}:\{temp path}\p4v\{workspace name}\{depot path}#{revision}.{extension}
Assuming a workspace name of "workspace",  a Windows user name "user_name" and a depot path of "//depot/foo.text" at revision 1, this temporary path is already 72 characters long:
C:\Users\user_name\AppData\Local\Temp\p4v\workspace\depot\foo.txt#1.text
This is true even though the workspace path could be as short as 16 characters:
 
X:\depot\foo.txt
 
There are two ways this can be addressed:
 
  • Reduce the length of the path to %TEMP%
Using the above example, the temp path is 38 characters. Use the technique described above to create a drive letter and set the TEMP and TMP values to use the substituted drive letter to drop 35 characters (or more if the user name is longer) from the path length. For example, if the TEMP directory is mapped to drive letter Q:
subst q: "C:\Users\user_name\AppData\Local\Temp\"
set TEMP=q:\
set TMP=q:\ 
To change the TEMP value for all applications see article 889541 in Microsoft's KB.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms682653(v=vs.85).aspx
  • Reduce the size of the workspace name
To prevent workspace naming collisions the workspace name is part of the path. If you use a long workspace name, be aware that this will add to the path length for every file synced.

Issues while resolving files

The resolve dialog may show the message 'Perforce could not resolve this file' when the path length exceeds MAX_PATH. Try shortening the workspace name, the client root or the path to %TEMP% as described above.
 

Example changing the proxy cache using linkd.exe 

The Perforce proxy server P4PCACHE variable does not recognize mapped drives. See "Services and Redirected Drives" in Microsoft's KB.

http://support.microsoft.com/kb/180362/

The linkd.exe command can be used to circumvent long paths as seen in:

http://support.microsoft.com/kb/205524

You can use a Windows link to change your proxy cache.

  1. Download linkd.exe from the Windows Server 2003 Resource Kit.

  2. Create a link to the actual proxy cache. Here we make "c:\a" a shorter path than "E:\Program Files\Perforce\Proxy".

    linkd c:\a "E:\Program Files\Perforce\Proxy"
    Link created at: c:\a
  3. Change the Perforce Proxy P4PCACHE variable to point to "c:\a" instead of the longer path name:

    p4 set -S "Perforce Proxy" P4PCACHE="c:\a"
  4. Stop and restart the Perforce Proxy.

Example using \\?\

You can also add \\?\ to the beginning of the existing file name to circumvent the Windows 260-character path limit. This addition enables you to create paths up to 32,000 characters in length.

There is a problem presented with this approach. The addition of \\?\ renders the file unusable to most other applications on your system. The application has to support \\?\ syntax. Furthermore, many .NET APIs are not able to work with this file. The \\?\ syntax works with the Win32 file-related APIs, but it does not work for general Win32 functions that accept paths (such as LoadLibrary).

It is therefore recommended that you use the subst workaround for the Windows OS 260-character path limit for submit before attempting the \\?\ syntax workaround.

More information

Please consult the Microsoft BCL Team Blog link below for further details on this issue:

http://blogs.msdn.com/bclteam/archive/2007/02/13/long-paths-in-net-part-1-of-3-kim-hamilton.aspx

Or see the Microsoft Developer site:

http://msdn.microsoft.com/en-us/library/aa365247.aspx

 

Related Links

Feedback

 

Was this article helpful?


   

Feedback

Please tell us how we can make this article more useful.

Characters Remaining: 255