Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting long paths #268

Open
phishyYy opened this issue Apr 24, 2024 · 10 comments
Open

Exporting long paths #268

phishyYy opened this issue Apr 24, 2024 · 10 comments

Comments

@phishyYy
Copy link

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?

@KevinJump
Copy link
Member

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

@phishyYy
Copy link
Author

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
Copy link
Author

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! :)

@KevinJump
Copy link
Member

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.

@phishyYy
Copy link
Author

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
Copy link
Author

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

@KevinJump
Copy link
Member

KevinJump commented Apr 25, 2024

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

@phishyYy
Copy link
Author

@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?

@KevinJump
Copy link
Member

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).

@phishyYy
Copy link
Author

@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!! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants