Webdav external storage wrong type when deleted files app is enabled

Hello,

Iā€™m developing a custom app for my Nextcloud instance that adds a new external storage backend option based on WebDAV, with some additional features. The integration works perfectly when connecting external storage using this new type. However, Iā€™m encountering issues when trying to perform WebDAV operations like creating a folder. Specifically, the process fails under certain conditions.

Workflow Overview:

  1. When a user registers via the Registration app, a hook is triggered.
  2. This hook iterates through all external storages of the custom type.
  3. If the backend type is WebDAV, a request is sent to create a specific folder.

The Issue:

Sometimes, instead of the expected storage type \OC\Files\Storage\DAV, the type is OCA\Files_Trashbin\Storage. Below is the relevant code snippet:

foreach ($externalStorages as $externalStorage) {
    if ($externalStorage->getBackend()->getIdentifier() != "customType") {
        continue;
    }

    if (!$externalStorage->getBackendOption('auto_create_folder')) {
        continue;
    }

    $mountPointInstance = $this->mountManager->find($externalStorage->getMountPoint());
    $storageClass = $externalStorage->getBackend()->getStorageClass();

    // Resolve the remote subfolder if it contains $user
    $storageArguments = $externalStorage->getBackendOptions();
    $resolvedMountpoint = str_replace('$user', $event->getUser()->getUID(), $externalStorage->getBackendOption('root'));
    $storageArguments['root'] = $resolvedMountpoint;

    // Get storage instance of type DAV to use mkdir and other functions
    $storage = $this->storageFactory->getInstance($mountPointInstance, $storageClass, $storageArguments);

    if ($storage instanceof DAV) {
        // Create folder
    }
}

When the type unexpectedly changes, disabling the ā€œDeleted filesā€ app resolves the issue, and everything functions correctly. However, re-enabling the app causes the failure to return.

Question:

Why would enabling the ā€œDeleted filesā€ app impact the storage type in this way? Is there something within my custom app or the Nextcloud environment that might be causing this interaction? Iā€™m uncertain whether the problem lies within my app, but without the proper type check, the WebDAV operations will fail.

Any insights would be greatly appreciated!

Thank you.

Hi Florian,

additional logic, like the trash bin, is implemented as storage wrapper around the actual storage.

Each storage implements the IStorage interface.

I think you are looking for server/lib/public/Files/Storage/IStorage.php at 3973a8f722c4acf5da82a611ee50f04e19627727 Ā· nextcloud/server Ā· GitHub.

1 Like

@kesselb do you mean, I need to replace the condition by using the instanceOfStorage function can fix this behavior ?

Yep, instanceOfStorage will look through the storage wrappers and tell you if the source storage is of the given type.

1 Like