uSyncMigrations icon indicating copy to clipboard operation
uSyncMigrations copied to clipboard

Exporting long paths

Open phishyYy opened this issue 1 year ago • 10 comments

I have a very long folder path and structure of my site that i'm trying to export and I get this error on some pages:

2024-04-24 16:16:42,087 [P7716/D2/T92] WARN Jumoo.uSync.BackOffice.uSyncEvents - Failed to save node: System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost) at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost) at Jumoo.uSync.BackOffice.Helpers.uSyncIOHelper.SaveNode(XElement node, String path) 2024-04-24 16:16:42,229 [P7716/D2/T92] WARN Jumoo.uSync.BackOffice.uSyncEvents - Failed to save node: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\A{project}\uSync\MigrationPacks{guid}\data\Content\home\positions\position-papers\positions-papers\consultative-document-on-global-systemically-important-banks-assessment-methodology-and-the-additional-loss-absorbency-requirement'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

Im trying to hack my way through using longPathEnabled registry key in windows but I cant seem to get the uSync .dll to respect the flag. Any ideas on what to do?

phishyYy avatar Apr 24 '24 14:04 phishyYy

Hi,

If this is an Umbraco 7 site, i think you can set the useshortnames setting in the uSync config (requires restart) and then it will hopefully write things out with shorter filenames.

https://github.com/KevinJump/uSync-Legacy/blob/out-of-support-main/docs/handler-config.md#custom-handler-actions

KevinJump avatar Apr 24 '24 14:04 KevinJump

Thanks for the quick answer @KevinJump .

I'll try that. I do depend on the path structure. I migrate the content do new document types at a later stage and I use the path to compare and old structure with old doctypes with new structure with new doctypes.

I'll se if I can make it work.

phishyYy avatar Apr 24 '24 14:04 phishyYy

Okay, that did work and the folders are now id:s.

Unfortunately I do need the paths as is. Is there anyway I can enable long paths or do you have any suggestions to solve it? I understand that my issue really is not an issue in most cases. Really appreciate the help! :)

phishyYy avatar Apr 25 '24 06:04 phishyYy

Hi,

if you have done the registry setting that applies to everything on the machine (think it might require a restart).

The content will still contain the path (in the file) for when it is imported, but if the names are super long its only the windows setting that can do anything about that.

This ? https://www.autodesk.com/support/technical/article/caas/sfdcarticles/sfdcarticles/The-Windows-10-default-path-length-limitation-MAX-PATH-is-256-characters.html#:~:text=To%20enable%20the%20long%20path,%5CCurrentControlSet%5CControl%5CFileSystem.

KevinJump avatar Apr 25 '24 08:04 KevinJump

Yeah exactly.

For some reason I can't get the package to respect the windows registry setting.

It works on my machine, tested it manually and on a console app.

So I can't figure out why the application does not. I also tried adding a manifest but the I can't seemt to attach it to the packaged .dll:s.

phishyYy avatar Apr 25 '24 08:04 phishyYy

Is there any way to get hold of the source code for the Packer package ?

phishyYy avatar Apr 25 '24 10:04 phishyYy

yes, they live here https://github.com/Jumoo/uSync.Migrations.Packers

KevinJump avatar Apr 25 '24 10:04 KevinJump

@KevinJump really appreciate your help man! Thx.

I just realized that the actual error happens here: Jumoo.uSync.BackOffice.Helpers.uSyncIOHelper.SaveNode(XElement node, String path). Or am I not understanding this correctly?

The current uSync package im using is 4.0.16 and that source code is not available right?

phishyYy avatar Apr 25 '24 11:04 phishyYy

Here : https://github.com/KevinJump/uSync-Legacy/blob/out-of-support-main/Jumoo.uSync.BackOffice/Helpers/uSyncIOHelper.cs#L30-L58

It all ends in a call to the framework method XElment.Save call, so I don't think this is an issue you can resolve in the source code, (other than chaning the path naming).

KevinJump avatar Apr 25 '24 11:04 KevinJump

@KevinJump I solved my issue by doing this in the SaveNode method in uSyncIOHelper:

if (File.Exists(path))
{
    ArchiveFile(path);

    // remove
    // File.Delete(path);
}
string folder = Path.GetDirectoryName(path);

// The prefix \\?\ tells windows to ignore long paths apparently.
string newFolderPath = @"\\?\" + folder;
string newPath = @"\\?\" + path;

//LogHelper.Warn<uSyncEvents>("Folder: {0}", () => newFolderPath);

if (!Directory.Exists(folder))
{
    Directory.CreateDirectory(newFolderPath);
}

LogHelper.Debug<uSyncIOHelper>("Saving XML to Disk: {0}", () => path);

uSyncEvents.fireSaving(new uSyncEventArgs { fileName = path });

node.Save(newPath);

uSyncEvents.fireSaved(new uSyncEventArgs { fileName = path });

This might not be a solution for everyone. It actually made some other stuff a bit harder like, zipping files for example. Had to use powershell to zip the folders.

But you helped me solve my issue, very much appreciated!! :)

phishyYy avatar Apr 26 '24 08:04 phishyYy