Using the server flag -Cn

Overriding the operating system's case-handling behavior.

WARNING:

Please note, use of -Cn is undocumented, and is subject to change or removal without prior notice. Consider using the p4migrate utility instead to translate case.  If you choose to use the -Cn flag, you must ALWAYS use this flag.  This is necessary both when starting your Perforce Server and when running checkpointing operations.  If you do not do so, you risk corrupting your Perforce database and/or your checkpoint and journal.

PROBLEM

What does the -Cn flag do?
When do I use it?


SOLUTION

The -Cn flag instructs the Perforce Server to override the operating system's case handling behavior for the Perforce database. The flag was introduced in release 2004.2, and is a server side flag. From the release notes:

Forces the server to operate in case-sensitive (n=0) on Windows or
case-insensitive (n=1) mode on Unix. -Cn2 is an experimental 'hybrid'
order: case folding but uniqueness preserving.

You use the -Cn flag when:

  • You want to change the way the Perforce Server handles the case, overriding the operating system's default case-handling.
  • You are migrating your Perforce Server to an operating system with a different case-handling method, but you wish to retain the existing method for case-handling.

You do NOT use the -Cn flag when:

  • You are not intending to override the operating system case-handling.

If you do not intend to override case-handling, you checkpoint the database, resolve any case conflicts and inconsistencies, then restore from this case-consistent checkpoint. This process is explained in more detail in Cross-Platform Server Migration.

You MUST NOT use -C0 or -C2 when:

  • running your Perforce Server on a Windows platform, and one file name or path differs from another only in case. This will corrupt the corresponding archive files.

When using either -C0 or -C2, the Perforce Server makes a distinction between "//depot/file.txt" and "//depot/FILE.TXT", and tells the operating system to write "file.txt,v" or "FILE.TXT,v" accordingly. Although Windows is capable of preserving the case used, it is unaware of the difference between these two names. Therefore, "file.txt,v" overwrites or is appended to "FILE.TXT,v", and so too for the reverse, causing loss or corruption of revision content.

If you have not created a database, you can simply start the Perforce Server using the appropriate -Cn flag.

For an existing database, you need to take a checkpoint of the database, then restore it including the appropriate -Cn flag in the "restore" command. This restore ensures that the order of the keys is appropriate for the case-handling.

Example

If the Perforce Server is on a case-sensitive platform and you want to run it in case-insensitive mode, you restore from a checkpoint using the -C1 flag:

p4d -r $P4ROOT -C1 -jr checkpoint.213

Now the server can be started with the correct -Cn flag, in this case -C1.

p4d -r $P4ROOT -p 1666 -C1

Important: The -Cn flag can only be used against new Perforce databases. Using the -Cn flag against a Perforce Server that is already in use instantly renders the keys out of order. Not only does it make the data largely inaccessible, it could easily cause the btree code enough confusion to corrupt the tree.

Notes:

The 2007.2 release of the Perforce Server checks the case order of the database on startup. If there is a mismatch, an error is reported in the log:

Perforce server error:
Database open error on db.counters!
BTree Case Order Mismatch

For a working example of using the -Cn flag see Moving from Windows to Linux, Retaining Case-handling.