Skip to content

[Bug]: Cannot write file version metadata when copying or moving a folder or file #53151

@bdovaz

Description

@bdovaz

⚠️ This issue respects the following points: ⚠️

Bug description

When a folder is copied or moved, the file events that arrives is of folder type, not of each file that has been copied or moved within the folder.

This causes that recursively it is necessary in that events to read with getDirectoryListing() all the nodes of type file.

It causes a race condition when using this API:

$this->versionManager->setMetadataValue($node, $node->getMTime(), 'author', $author);

Did expect one result but found none when executing: query \"SELECT * FROM `*PREFIX*files_versions` WHERE (`file_id` = :dcValue1) AND (`timestamp` = :dcValue2)\"

It would be solved by creating a VersionCreatedEvent event similar to VersionRestoredEvent.

This way we are always sure that when we are going to write the metadata of a version is the right time and solve the fragility that the timestamp / revision field is mapped to node->getMTime() and sometimes make it impossible for you to obtain a file version for that + 1 in catch:

$versionEntity->setTimestamp($versionEntity->getTimestamp() + 1);

Steps to reproduce

  1. Copy or move a folder with files in it.
  2. Subscribe to the NodeWrittenEvent event and call the $this->versionManager->setMetadataValue API.
  3. Check that the error occurs.
Did expect one result but found none when executing: query \"SELECT * FROM `*PREFIX*files_versions` WHERE (`file_id` = :dcValue1) AND (`timestamp` = :dcValue2)\"

Expected behavior

It should allow you to use the $this->versionManager->setMetadataValue API without errors.

Nextcloud Server version

31

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.3

Web server

None

Database engine version

None

Is this bug present after an update or on a fresh install?

None

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?

  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other

Configuration report

List of activated Apps

Nextcloud Signing status

Nextcloud Logs

Additional info

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions