You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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())
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.
Description of Issue
If a layer's identifier changes, it is not marked dirty.
OpenUSD/pxr/usd/sdf/layer.cpp
Line 5004 in 9b0c13b
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--
ArResolver
instead ofTfPathUtils
to arbitrate whether or not the layer exists already.Steps to Reproduce
Save()
reports as being successful even though the contents of layer2 are empty.System Information (OS, Hardware)
Linux
Package Versions
Build Flags
The text was updated successfully, but these errors were encountered: