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

Layers Not Marked as Dirty When Identifier Changes #3386

Open
nvmkuruc opened this issue Oct 30, 2024 · 1 comment
Open

Layers Not Marked as Dirty When Identifier Changes #3386

nvmkuruc opened this issue Oct 30, 2024 · 1 comment
Labels
needs review Issue needing input/review by the repo maintainer (Pixar)

Comments

@nvmkuruc
Copy link
Collaborator

nvmkuruc commented Oct 30, 2024

Description of Issue

If a layer's identifier changes, it is not marked dirty.

if (!force && !IsDirty() && TfPathExists(path))

SdfLayer::Save will early exit if a layer isn't dirty and if the resolved path exists on the file system. As such, it can report a successful save, even when the layer was not written.

We would recommend--

  • Changing the identifier of a layer marks it as dirty
  • Additionally, as of AR 2.0, it cannot be assumed that the resolved path is a file system path. Use ArResolver instead of TfPathUtils to arbitrate whether or not the layer exists already.

Steps to Reproduce

  1. Run the following python script. The only difference between the two blocks is that in the second block we touch the file path to ensure the file exists on disk.
import pathlib
import tempfile

from pxr import Sdf
from pxr import Usd


with tempfile.TemporaryDirectory() as temp_directory:
    file_path = pathlib.Path(temp_directory) / "new_layer.sdf"
    layer = Sdf.Layer.CreateAnonymous()
    layer.identifier = str(file_path.absolute())
    print("layer1>>", layer, file_path.exists(), layer.dirty)
    print("layer1>>", layer.Save())
    print("layer1>>", open(file_path).read())


with tempfile.TemporaryDirectory() as temp_directory:
    file_path = pathlib.Path(temp_directory) / "new_layer.sdf"
    file_path.touch()
    layer = Sdf.Layer.CreateAnonymous()
    layer.identifier = str(file_path.absolute())
    print("layer2>>", layer, file_path.exists(), layer.dirty)
    print("layer2>>", layer.Save())
    print("layer2>>", open(file_path).read())
  1. You should see the following output. In both cases, the layer is not considered dirty. The only difference is whether or not the path exists already. Note that in both cases Save() reports as being successful even though the contents of layer2 are empty.
layer1>> Sdf.Find('/tmp/tmph2n53a8g/new_layer.sdf') False False
layer1>> True
layer1>> #sdf 1.4.32


layer2>> Sdf.Find('/tmp/tmp2j4hxpbf/new_layer.sdf') True False
layer2>> True
layer2>>

System Information (OS, Hardware)

Linux

Package Versions

Build Flags

@jesschimein
Copy link
Collaborator

Filed as internal issue #USD-10374

@nvmkuruc nvmkuruc added the needs review Issue needing input/review by the repo maintainer (Pixar) label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review Issue needing input/review by the repo maintainer (Pixar)
Projects
None yet
Development

No branches or pull requests

2 participants