Skip to content

Layers Not Marked as Dirty When Identifier Changes #3386

@nvmkuruc

Description

@nvmkuruc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs reviewIssue needing input/review by the repo maintainer (Pixar)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions