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

LayerManager: Prevent unintended overwriting of unmodified USD layers at Maya save. #4027

Merged

Conversation

jufrantz
Copy link
Contributor

@jufrantz jufrantz commented Dec 3, 2024

The MayaUsd::utils::saveLayerWithFormat function uses two approaches to save USD data, depending on the layer file format:

  • Matching file format:
    If the layer file's format matches the user's preferences, the function calls SdfLayer::Save(). By default, Save() does not overwrite the file unless the layer has been modified.

  • Mismatched file format:
    If the file format differs from the user's preferences, the function uses SdfLayer::Export() to save the layer to the file. Unlike Save(), Export() always writes to the file, even if the layer hasn’t been modified in memory, potentially overwriting more recent changes on disk.

With this PR, LayerDatabase::saveUsdToUsdFiles now performs a "dirty" check to ensure that only modified layers are saved (exported). This change is particularly important in the context of Maya saves. Since Maya-usd v0.30, all layers used by the stage - including referenced layers - are considered during save. Large assembled stages may involve thousands of files in varying formats, this check is crucial to prevent unintended overwrites and data loss.

Additionally, this logic now better aligns with LayerDatabase::saveUsdToMayaFile.

A downside is that forcing a file format change during a save without modifications is no longer straightforward, but this is a minor concern compared to preventing data loss.

@seando-adsk seando-adsk added the workflows Related to in-context workflows label Dec 5, 2024
@seando-adsk seando-adsk assigned jufrantz and unassigned jufrantz Dec 5, 2024
@seando-adsk seando-adsk added the ready-for-merge Development process is finished, PR is ready for merge label Dec 6, 2024
@seando-adsk seando-adsk merged commit 7c22372 into Autodesk:dev Dec 6, 2024
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge Development process is finished, PR is ready for merge workflows Related to in-context workflows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants