Wednesday 3 November 2010

Sync error with utf16 filetype

When syncing or reverting a utf16 file, I am getting the following error:

Translation of file content failed near line 1

In 2007.2 release, a new utf16 filetype was introduced. When a file is added using a 2007.2 or greater client to a 2007.2 or greater server, Perforce looks for the UTF16 BOM (the 2 first bytes of the file), if there is a match the file will be detected as "utf16".

On submit, a unicode translation from utf16 to utf8 takes place and the file is stored on the server in utf8 regardless of whether the server is running in internationalized mode or not.

To take full advantage of the "utf16" filetype feature, a 2007.2 client (or higher) is required. Utf16 files added by pre-2007.2 clients are detected as binary and utf16 files synced by pre-2007.2 clients will be stored on the client in utf8.

A problem might arise after adding a utf16 file with a 2007.2 client (or higher) and submiting the file with a pre-2007.2 client. As the file will be sent without any utf16 to utf8 translation, the file will be stored on the server in utf16, causing the translation error on sync as well as a revert, as the depot file is not in utf8 as expected. A variant of this issue will happen when checking out a utf16 file with a pre-2007.2 client, then changing the utf8 content of the synced file to utf16. Upon submit, the "Translation of file content failed" errors will be shown.

To fix this issue, the filetype of the problem revisions needs to be changed to "binary" using the unsupported p4 retype command (see p4 help retype for details):

p4 retype -t binary

To detect which depot files might be affected by this issue run:

find -type f -name '*,v' | xargs grep -al $'\xFF\xFE'

Note: find, xargs, and grep are Unix commands and not natively available on the Windows environment. External Windows ports of Unix tools might allow you to run these commands within the Windows environment.

To avoid seeing this issue in future, all users should upgrade their Perforce client to the latest release.


View the original article here

No comments:

Post a Comment