nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.39k stars 4.07k forks source link

[Bug]: basicOperation(): Argument #2 ($path) must be of type string, null given #40090

Closed simonspa closed 2 months ago

simonspa commented 1 year ago

⚠️ This issue respects the following points: ⚠️

Bug description

Yesterday, the below stack trace appeared several hundred times in my Nextcloud 27.0.2 log. From the trace I infer that user BBBB shared an ODS file with user AAAA and the latter is trying to open it (or save it? The user agent is "COOLWSD".)

Whatever is happening, in the end a method requests a string but obtains null.

Steps to reproduce

(log entries)

Expected behavior

The requested operation succeeds.

Installation method

Community Manual installation with Archive

Nextcloud Server version

27

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.1

Web server

Nginx

Database engine version

MariaDB

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

Upgraded to a MAJOR version (ex. 22 to 23)

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

What user-backends are you using?

Configuration report

{
    "system": {
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "my.domain.tld"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "data-fingerprint": "58897020af7835d5d5eebe9f70033c28",
        "dbtype": "mysql",
        "version": "27.0.2.1",
        "overwrite.cli.url": "https:\/\/my.domain.tld",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "3306",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "htaccess.RewriteBase": "\/",
        "mail_smtpsecure": "ssl",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "465",
        "log_rotate_size": "104857600",
        "mail_smtpauthtype": "LOGIN",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 0,
            "password": "***REMOVED SENSITIVE VALUE***",
            "timeout": 0
        },
        "memcache.local": "\\OC\\Memcache\\APCu",
        "maintenance": false,
        "preview_max_y": 2048,
        "preview_max_x": 2048,
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "mail_smtpauth": 1,
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "knowledgebaseenabled": false,
        "loglevel": 2,
        "filelocking.enabled": "true",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "updater.release.channel": "stable",
        "activity_expire_days": 90,
        "mail_smtpmode": "smtp",
        "theme": "",
        "trusted_proxies": "***REMOVED SENSITIVE VALUE***",
        "app_install_overwrite": [
            "files_downloadactivity"
        ],
        "memcache.distributed": "\\OC\\Memcache\\Redis",
    }
}

List of activated Apps

Enabled:
  - activity: 2.19.0
  - admin_audit: 1.17.0
  - bookmarks: 13.1.1
  - bruteforcesettings: 2.7.0
  - calendar: 4.4.4
  - cloud_federation_api: 1.10.0
  - comments: 1.17.0
  - contacts: 5.3.2
  - contactsinteraction: 1.8.0
  - dashboard: 7.7.0
  - dav: 1.27.0
  - event_update_notification: 2.2.0
  - federatedfilesharing: 1.17.0
  - federation: 1.17.0
  - files: 1.22.0
  - files_downloadactivity: 1.16.0
  - files_pdfviewer: 2.8.0
  - files_rightclick: 1.6.0
  - files_sharing: 1.19.0
  - files_trashbin: 1.17.0
  - files_versions: 1.20.0
  - logreader: 2.12.0
  - lookup_server_connector: 1.15.0
  - metadata: 0.19.0
  - notes: 4.8.1
  - notifications: 2.15.0
  - notify_push: 0.6.3
  - oauth2: 1.15.1
  - password_policy: 1.17.0
  - passwords: 2023.8.31
  - photos: 2.3.0
  - previewgenerator: 5.3.0
  - privacy: 1.11.0
  - provisioning_api: 1.17.0
  - quota_warning: 1.17.0
  - richdocuments: 8.1.1
  - serverinfo: 1.17.0
  - settings: 1.9.0
  - sharebymail: 1.17.0
  - spreed: 17.0.3
  - tasks: 0.15.0
  - text: 3.8.0
  - theming: 2.2.0
  - theming_customcss: 1.14.0
  - twofactor_backupcodes: 1.16.0
  - twofactor_totp: 9.0.0
  - twofactor_webauthn: 1.2.0
  - updatenotification: 1.17.0
  - user_migration: 4.0.1
  - user_status: 1.7.0
  - viewer: 2.1.0
  - weather_status: 1.7.0
  - workflowengine: 2.9.0
Disabled:
  - circles: 27.0.1 (installed 25.0.0)
  - encryption: 2.15.0
  - files_external: 1.19.0 (installed 1.10.0)
  - firstrunwizard: 2.16.0 (installed 2.9.0)
  - nextcloud_announcements: 1.16.0 (installed 1.5.0)
  - recommendations: 1.6.0 (installed 0.4.0)
  - related_resources: 1.2.0 (installed 1.0.3)
  - support: 1.10.0 (installed 1.0.0)
  - survey_client: 1.15.0 (installed 0.1.5)
  - systemtags: 1.17.0 (installed 1.15.0)
  - user_ldap: 1.17.0

Nextcloud Signing status

No errors have been found.

Nextcloud Logs

{
    "reqId": "PoA62VVnraMBqx6nXJ1e",
    "level": 3,
    "time": "2023-08-28T22:49:24+02:00",
    "remoteAddr": "2a03:4000:2:bc5::1",
    "user": "AAAA",
    "app": "index",
    "method": "POST",
    "url": "/index.php/apps/richdocuments/wopi/files/5040041_oc0e7rzi20xo/contents?access_token=MCqDcyRRHu2FoEazjmUCoxqKnLEVgh4G&access_token_ttl=1693289762000",
    "message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 518 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1110",
    "userAgent": "COOLWSD HTTP Agent 23.05.2.2",
    "version": "27.0.2.1",
    "exception":
    {
        "Exception": "Exception",
        "Message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 518 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1110",
        "Code": 0,
        "Trace":
        [
            {
                "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
                "line": 183,
                "function": "dispatch",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->",
                "args":
                [
                    [
                        "OCA\\Richdocuments\\Controller\\WopiController"
                    ],
                    "putFile"
                ]
            },
            {
                "file": "/var/www/nextcloud/lib/private/Route/Router.php",
                "line": 315,
                "function": "main",
                "class": "OC\\AppFramework\\App",
                "type": "::",
                "args":
                [
                    "OCA\\Richdocuments\\Controller\\WopiController",
                    "putFile",
                    [
                        "OC\\AppFramework\\DependencyInjection\\DIContainer"
                    ],
                    [
                        "5040041_oc0e7rzi20xo",
                        "richdocuments.wopi.putFile"
                    ]
                ]
            },
            {
                "file": "/var/www/nextcloud/lib/base.php",
                "line": 1071,
                "function": "match",
                "class": "OC\\Route\\Router",
                "type": "->",
                "args":
                [
                    "/apps/richdocuments/wopi/files/5040041_oc0e7rzi20xo/contents"
                ]
            },
            {
                "file": "/var/www/nextcloud/index.php",
                "line": 36,
                "function": "handleRequest",
                "class": "OC",
                "type": "::",
                "args":
                []
            }
        ],
        "File": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
        "Line": 169,
        "Previous":
        {
            "Exception": "TypeError",
            "Message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 518",
            "Code": 0,
            "Trace":
            [
                {
                    "file": "/var/www/nextcloud/lib/private/Files/View.php",
                    "line": 518,
                    "function": "basicOperation",
                    "class": "OC\\Files\\View",
                    "type": "->",
                    "args":
                    [
                        "file_exists",
                        null
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/Filesystem.php",
                    "line": 545,
                    "function": "file_exists",
                    "class": "OC\\Files\\View",
                    "type": "->",
                    "args":
                    [
                        null
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/files_versions/lib/Storage.php",
                    "line": 189,
                    "function": "file_exists",
                    "class": "OC\\Files\\Filesystem",
                    "type": "::",
                    "args":
                    [
                        null
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
                    "line": 210,
                    "function": "store",
                    "class": "OCA\\Files_Versions\\Storage",
                    "type": "::",
                    "args":
                    [
                        null
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
                    "line": 107,
                    "function": "write_hook",
                    "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
                    "type": "->",
                    "args":
                    [
                        [
                            "OC\\Files\\Node\\File"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/EventDispatcher/ServiceEventListener.php",
                    "line": 86,
                    "function": "handle",
                    "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
                    "line": 251,
                    "function": "__invoke",
                    "class": "OC\\EventDispatcher\\ServiceEventListener",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ],
                        "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent",
                        [
                            "Symfony\\Component\\EventDispatcher\\EventDispatcher"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
                    "line": 73,
                    "function": "callListeners",
                    "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
                    "type": "->",
                    "args":
                    [
                        [
                            [
                                "Closure"
                            ]
                        ],
                        "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent",
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
                    "line": 94,
                    "function": "dispatch",
                    "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ],
                        "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
                    "line": 106,
                    "function": "dispatch",
                    "class": "OC\\EventDispatcher\\EventDispatcher",
                    "type": "->",
                    "args":
                    [
                        "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent",
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/Node/HookConnector.php",
                    "line": 112,
                    "function": "dispatchTyped",
                    "class": "OC\\EventDispatcher\\EventDispatcher",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCP\\Files\\Events\\Node\\BeforeNodeWrittenEvent"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/legacy/OC_Hook.php",
                    "line": 105,
                    "function": "write",
                    "class": "OC\\Files\\Node\\HookConnector",
                    "type": "->",
                    "args":
                    [
                        [
                            "/Documents/SomeDocuments.ods",
                            true
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/View.php",
                    "line": 588,
                    "function": "emit",
                    "class": "OC_Hook",
                    "type": "::",
                    "args":
                    [
                        "OC_Filesystem",
                        "write",
                        [
                            "/Documents/SomeDocument.ods",
                            true
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/View.php",
                    "line": 629,
                    "function": "emit_file_hooks_pre",
                    "class": "OC\\Files\\View",
                    "type": "->",
                    "args":
                    [
                        true,
                        "/BBBB/files/Documents/SomeDocument.ods",
                        true
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/Node/File.php",
                    "line": 73,
                    "function": "file_put_contents",
                    "class": "OC\\Files\\View",
                    "type": "->",
                    "args":
                    [
                        "/BBBB/files/Documents/SomeDocument.ods",
                        null
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 504,
                    "function": "putContent",
                    "class": "OC\\Files\\Node\\File",
                    "type": "->",
                    "args":
                    [
                        null
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 786,
                    "function": "OCA\\Richdocuments\\Controller\\{closure}",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->",
                    "args":
                    [
                        "*** sensitive parameters replaced ***"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 763,
                    "function": "retryOperation",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->",
                    "args":
                    [
                        [
                            "Closure"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Files/Lock/LockManager.php",
                    "line": 29,
                    "function": "OCA\\Richdocuments\\Controller\\{closure}",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->",
                    "args":
                    [
                        "*** sensitive parameters replaced ***"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 766,
                    "function": "runInScope",
                    "class": "OC\\Files\\Lock\\LockManager",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCP\\Files\\Lock\\LockContext"
                        ],
                        [
                            "Closure"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                    "line": 505,
                    "function": "wrappedFilesystemOperation",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCA\\Richdocuments\\Db\\Wopi",
                            308
                        ],
                        [
                            "Closure"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
                    "line": 230,
                    "function": "putFile",
                    "class": "OCA\\Richdocuments\\Controller\\WopiController",
                    "type": "->",
                    "args":
                    [
                        "5040041",
                        "MCqDcyRRHu2FoEazjmUCoxqKnLEVgh4G"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
                    "line": 137,
                    "function": "executeController",
                    "class": "OC\\AppFramework\\Http\\Dispatcher",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCA\\Richdocuments\\Controller\\WopiController"
                        ],
                        "putFile"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
                    "line": 183,
                    "function": "dispatch",
                    "class": "OC\\AppFramework\\Http\\Dispatcher",
                    "type": "->",
                    "args":
                    [
                        [
                            "OCA\\Richdocuments\\Controller\\WopiController"
                        ],
                        "putFile"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/private/Route/Router.php",
                    "line": 315,
                    "function": "main",
                    "class": "OC\\AppFramework\\App",
                    "type": "::",
                    "args":
                    [
                        "OCA\\Richdocuments\\Controller\\WopiController",
                        "putFile",
                        [
                            "OC\\AppFramework\\DependencyInjection\\DIContainer"
                        ],
                        [
                            "5040041_oc0e7rzi20xo",
                            "richdocuments.wopi.putFile"
                        ]
                    ]
                },
                {
                    "file": "/var/www/nextcloud/lib/base.php",
                    "line": 1071,
                    "function": "match",
                    "class": "OC\\Route\\Router",
                    "type": "->",
                    "args":
                    [
                        "/apps/richdocuments/wopi/files/5040041_oc0e7rzi20xo/contents"
                    ]
                },
                {
                    "file": "/var/www/nextcloud/index.php",
                    "line": 36,
                    "function": "handleRequest",
                    "class": "OC",
                    "type": "::",
                    "args":
                    []
                }
            ],
            "File": "/var/www/nextcloud/lib/private/Files/View.php",
            "Line": 1110
        },
        "CustomMessage": "--"
    },
    "id": "64ed996b3fa81"
}

Additional info

No response

bjo81 commented 1 year ago

@simonspa Do you also expierence the issue that COOL is unable to save the document then? In our case a user creates a file in COOL, but when he want's to save it, the issue appears.

simonspa commented 1 year ago

That's a good question @bjo81 that I unfortunately cannot really answer. This only happened in other user sessions so far and I have only observed the above message in the log. I don't know how the UX is in that moment. I will try to inquire with them but since it's been a few days they might not remember.

SystemKeeper commented 1 year ago

I've seen this as well and thought it was an issue in the richdocuments app at first (see https://github.com/nextcloud/richdocuments/issues/3169), but it looks like it's something with the files_version app.

In my case the file in question was shared from a groupfolder, but looking at the enabled apps above, groupfolders are not enabled on your installation, is that correct? So in that case, I can remove groupfolders as the responsible app in my thinking.

The error does appear when the user tries to save a (shared with him) document. Sometimes a message pops up saying something about missing permissions and unable to save. The changes are then lost.

I've seen this on 27.0.2 and also on 27.1 RC2.

Also CC @artonge

simonspa commented 1 year ago

I can definitely confirm that I do not have the group folders app enabled.

SystemKeeper commented 1 year ago

I am wondering if the try-catch is enough here:

https://github.com/nextcloud/server/blob/cec0b310a5af84d5afae4afa2449840dcdca56be/apps/files_versions/lib/Listener/FileEventsListener.php#L357-L365

if I understand correctly, this calls getRelativePath from OC\Files\Utils\PathHelper (?) but this can return null instead of throwing an exception?

https://github.com/nextcloud/server/blob/aa241df161054588293dde038104e670626f88e5/lib/private/Files/Utils/PathHelper.php#L38-L45

But that's just blind guessing on my end since I am not familiar with the code. On my testinstance I have disabled files_versions app for now and it seems to work fine now... Let's see.

AIlkiv commented 1 year ago

@artonge Hi. Can you please take a look?

There is a method OCA\Files_Versions\Listener\FileEventsListener::getPathForNode, and it appears that you have created it (commit: https://github.com/nextcloud/server/commit/3da63f4148898ec4bc9544a4a9ef07bac3e07669).

I have studied the operation of this method, and I believe it would make sense to remove the exception handling from it.

Why?

Example 1

Alice has the file Alice\files\study\homework.odt (file in folder). She shared this file with Bob. Bob is editing this file. When saved, $node->getPath() in the getPathForNode method will have the value "Bob\files\homework.odt". If it was not possible to connect to the Bob folder. Will try to get RelativePath from Bob\files\homework.odt relative to Alice\files and it will return null As a result, we will get the error that the author of this issue complains about.

Example 2

I thought it would make sense to rewrite the exception handling:

$ownerFolder = $this->rootFolder->getUserFolder($node->getOwner()->getUid());
$ownerNode = $ownerFolder->getById($node->getId());

return $ownerFolder->getRelativePath($ownerNode ->getPath());

\study\homework.odt will then be returned

And then in the OCA\Files_Versions\Store::store method there is a Filesystem::file_exists($filename) check against Bob (he has \homework.odt, not \study\homework.odt). As a result, Store::store will not work correctly.

Based on these two cases, I have the impression that the system will work more smoothly without handling this exception.

} catch (\Throwable $ex) {
    return $this->rootFolder
        ->getUserFolder($node->getOwner()->getUid())
        ->getRelativePath($node->getPath());
}

But I have relatively recently started studying Nextcloud, so I would be very grateful if you could evaluate the correctness of these conclusions.

jolly-jump commented 1 year ago

Hi @AIlkiv I do barely understand, what you are doing. But I was desperately in need of a solution and used your rewrite: it works for me (!). You don't need the second line, though? $ownerNode will not be used in the following lines. Cheers, Tobias

jolly-jump commented 1 year ago

I've seen this on 27.0.2 and also on 27.1 RC2.

Also CC @artonge

Beside myself having the problem: see here I found another user from long time/version ago: https://help.nextcloud.com/t/collabora-on-mobile-cant-save-edited-documents-in-shared-folders/69272/2 Even if the bug is not that old, is there a chance to get this fixed without having to disable files_versions ?

AIlkiv commented 1 year ago

I do barely understand, what you are doing. But I was desperately in need of a solution and used your rewrite: it works for me (!). You don't need the second line, though? $ownerNode will not be used in the following lines.

This is not a solution. It should not be used.

There was a mistake, I corrected the comment return $ownerFolder->getRelativePath($ownerNode->getPath());.

jolly-jump commented 1 year ago

Hi @AIlkiv , thanks for the correction. However, I tried a couple of things and the main problem is indeed that getRelativePath() is empty - iff the path of the node does not fit to the current user.

So, from where my problem comes: $node->getPath() is already Alice\files\study\homework.odt . This seems to be a problem steming from the richdocuments-App.... the same thing in the browser, and $node->getPath() is Bob\...

And one more thing: your proposal does not work, since $ownerFolder->getById($node->getId()) returns an array of possible Nodes/Folders. One would have to adjust this atleast.

I have used this workaround now:

        private function getPathForNode(Node $node): ?string {
                $ownerFolder = $this->rootFolder->getUserFolder($node->getOwner()->getUid());
                try {   
                        $relativepath = $this->rootFolder
                                ->getUserFolder(\OC_User::getUser())
                                ->getRelativePath($node->getPath());
                        if ($relativepath === null) {
                                $this->logger->error('Relative Path null of Node Path: ' . $node->getPath() . '; User: ' . \OC_User::getUser());
                                $relativepath = $ownerFolder->getRelativePath($node->getPath());
                        }
                } catch (\Throwable $ex) {
                        $relativepath = $ownerFolder->getRelativePath($node->getPath());
                }
                return $relativepath;
        }
AIlkiv commented 1 year ago

@jolly-jump In which case path may not be from the current user?

I checked the following situations:

  1. when editing its own file.
  2. when editing a shared file.

In both cases, I had the correct path.

jolly-jump commented 1 year ago

@AIlkiv

I am talking about the situation, where bob edits a file shared from alice.

I admit, I haven't tested a subdirectory like "study" in the account of Alice.

Thus: for the webediting everything works already out of the box (the try-part of the exception handling works). For the mobile editing part, the try-part works as well and does not throw an exception, but the relativePath-string is "null", since $node is already the "$ownerNode".

Thus the "catch"-part is never reached (in these two situations).

kyrofa commented 11 months ago

I get this error trying to run encryption:encrypt-all:

$ php occ encryption:encrypt-all"
You are about to encrypt all files stored in your Nextcloud installation.
Depending on the number of available files, and their size, this may take quite some time.
Please ensure that no user accesses their files during this time!
Note: The encryption module you use determines which files get encrypted.

Do you really want to continue? (y/n) y

Encrypt all files with the Default encryption module
====================================================

Create key-pair for every user
------------------------------

This module will encrypt all files in the users files folder initially.
Already existing versions and files in the trash bin will not be encrypted.

 Key-pair created for all users 
 [->--------------------------]

Generated encryption key passwords
----------------------------------

All users already had a key-pair, no further action needed.

Start to encrypt users files
----------------------------

 %message% 
 [>---------------------------]An unhandled exception has been thrown:
TypeError: OC\Files\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/html/lib/private/Files/View.php on line 528 and defined in /var/www/html/lib/private/Files/View.php:1128
Stack trace:
#0 /var/www/html/lib/private/Files/View.php(528): OC\Files\View->basicOperation('file_exists', NULL)
#1 /var/www/html/apps/files_versions/lib/Listener/FileEventsListener.php(345): OC\Files\View->file_exists(NULL)
#2 /var/www/html/apps/files_versions/lib/Listener/FileEventsListener.php(132): OCA\Files_Versions\Listener\FileEventsListener->pre_renameOrCopy_hook(Object(OC\Files\Node\File), Object(OC\Files\Node\File))
#3 /var/www/html/lib/private/EventDispatcher/ServiceEventListener.php(86): OCA\Files_Versions\Listener\FileEventsListener->handle(Object(OCP\Files\Events\Node\BeforeNodeRenamedEvent))
#4 /var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php(251): OC\EventDispatcher\ServiceEventListener->__invoke(Object(OCP\Files\Events\Node\BeforeNodeRenamedEvent), 'OCP\\Files\\Event...', Object(Symfony\Component\EventDispatcher\EventDispatcher))
#5 /var/www/html/3rdparty/symfony/event-dispatcher/EventDispatcher.php(73): Symfony\Component\EventDispatcher\EventDispatcher->callListeners(Array, 'OCP\\Files\\Event...', Object(OCP\Files\Events\Node\BeforeNodeRenamedEvent))
#6 /var/www/html/lib/private/EventDispatcher/EventDispatcher.php(94): Symfony\Component\EventDispatcher\EventDispatcher->dispatch(Object(OCP\Files\Events\Node\BeforeNodeRenamedEvent), 'OCP\\Files\\Event...')
#7 /var/www/html/lib/private/EventDispatcher/EventDispatcher.php(106): OC\EventDispatcher\EventDispatcher->dispatch('OCP\\Files\\Event...', Object(OCP\Files\Events\Node\BeforeNodeRenamedEvent))
#8 /var/www/html/lib/private/Files/Node/HookConnector.php(187): OC\EventDispatcher\EventDispatcher->dispatchTyped(Object(OCP\Files\Events\Node\BeforeNodeRenamedEvent))
#9 /var/www/html/lib/private/legacy/OC_Hook.php(105): OC\Files\Node\HookConnector->rename(Array)
#10 /var/www/html/lib/private/Files/View.php(760): OC_Hook::emit('OC_Filesystem', 'rename', Array)
#11 /var/www/html/apps/encryption/lib/Crypto/EncryptAll.php(302): OC\Files\View->rename('/christopher@mi...', '/christopher@mi...')
#12 /var/www/html/apps/encryption/lib/Crypto/EncryptAll.php(274): OCA\Encryption\Crypto\EncryptAll->encryptFile('/christopher@mi...')
#13 /var/www/html/apps/encryption/lib/Crypto/EncryptAll.php(222): OCA\Encryption\Crypto\EncryptAll->encryptUsersFiles('christopher@mir...', Object(Symfony\Component\Console\Helper\ProgressBar), 'christopher@mir...')
#14 /var/www/html/apps/encryption/lib/Crypto/EncryptAll.php(168): OCA\Encryption\Crypto\EncryptAll->encryptAllUsersFiles()
#15 /var/www/html/apps/encryption/lib/Crypto/Encryption.php(551): OCA\Encryption\Crypto\EncryptAll->encryptAll(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/html/core/Command/Encryption/EncryptAll.php(116): OCA\Encryption\Crypto\Encryption->encryptAll(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /var/www/html/3rdparty/symfony/console/Command/Command.php(298): OC\Core\Command\Encryption\EncryptAll->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /var/www/html/3rdparty/symfony/console/Application.php(1040): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /var/www/html/3rdparty/symfony/console/Application.php(301): Symfony\Component\Console\Application->doRunCommand(Object(OC\Core\Command\Encryption\EncryptAll), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /var/www/html/3rdparty/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /var/www/html/lib/private/Console/Application.php(211): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /var/www/html/console.php(100): OC\Console\Application->run()
#23 /var/www/html/occ(11): require_once('/var/www/html/c...')
#24 {main}command terminated with exit code 1

Any idea what's happening, here?

jakobroehrl commented 11 months ago

When I disable the version app, the problem is solved. The version of the version app is 1.20.0 Is this solved in a newer version?

artonge commented 11 months ago

Could one of you, that experience the issue, apply the following patch and check what kind of file causes the issue for them? This will create a log when getPathForNode return a null value.

null_path_files_versions_hook.txt

SystemKeeper commented 11 months ago

Applied the patch and re-enabled files_versions. Lets see. I was unable to reproduce it on purpose, only when someone complained that the data they entered in Nextcloud Office was lost.

@jakobroehrl Is it reproducable for you each time?

SystemKeeper commented 11 months ago

That was fast, logged the error below. Just to mention it, this happens for me when trying to edit a shared document from the iOS Files app. And I see that @jakobroehrl linked to the Android app. Maybe there's something different when opening richdocuments in a webview in contrast to accessing it through the nextcloud UI?

{
    "reqId": "OBWbUL7unF4Oo5oYPnws",
    "level": 3,
    "time": "2023-12-14T17:50:50+01:00",
    "remoteAddr": "172.30.150.2",
    "user": "test",
    "app": "richdocuments",
    "method": "POST",
    "url": "//index.php/apps/richdocuments/wopi/files/866619_oc4r8rpp6vq8/contents?access_token=....&access_token_ttl=1702608560000",
    "message": see below
    "userAgent": "COOLWSD HTTP Agent 23.05.5.4",
    "version": "28.0.0.11"
}

Exception:

{
    "Exception": "Exception",
    "Message": "Object of class OC\\User\\LazyUser could not be converted to string in file '/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php' line 197",
    "Code": 0,
    "Trace": [
        {
            "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
            "line": 184,
            "function": "dispatch",
            "class": "OC\\AppFramework\\Http\\Dispatcher",
            "type": "->"
        },
        {
            "file": "/var/www/nextcloud/lib/private/Route/Router.php",
            "line": 315,
            "function": "main",
            "class": "OC\\AppFramework\\App",
            "type": "::"
        },
        {
            "file": "/var/www/nextcloud/lib/base.php",
            "line": 1069,
            "function": "match",
            "class": "OC\\Route\\Router",
            "type": "->"
        },
        {
            "file": "/var/www/nextcloud/index.php",
            "line": 39,
            "function": "handleRequest",
            "class": "OC",
            "type": "::"
        }
    ],
    "File": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
    "Line": 169,
    "Previous": {
        "Exception": "Error",
        "Message": "Object of class OC\\User\\LazyUser could not be converted to string",
        "Code": 0,
        "Trace": [
            {
                "file": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
                "line": 102,
                "function": "write_hook",
                "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/EventDispatcher/ServiceEventListener.php",
                "line": 86,
                "function": "handle",
                "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
                "line": 230,
                "function": "__invoke",
                "class": "OC\\EventDispatcher\\ServiceEventListener",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
                "line": 59,
                "function": "callListeners",
                "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
                "line": 94,
                "function": "dispatch",
                "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
                "line": 106,
                "function": "dispatch",
                "class": "OC\\EventDispatcher\\EventDispatcher",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/Files/Node/HookConnector.php",
                "line": 100,
                "function": "dispatchTyped",
                "class": "OC\\EventDispatcher\\EventDispatcher",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/legacy/OC_Hook.php",
                "line": 105,
                "function": "write",
                "class": "OC\\Files\\Node\\HookConnector",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/Files/View.php",
                "line": 596,
                "function": "emit",
                "class": "OC_Hook",
                "type": "::"
            },
            {
                "file": "/var/www/nextcloud/lib/private/Files/View.php",
                "line": 639,
                "function": "emit_file_hooks_pre",
                "class": "OC\\Files\\View",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/Files/Node/File.php",
                "line": 73,
                "function": "file_put_contents",
                "class": "OC\\Files\\View",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                "line": 512,
                "function": "putContent",
                "class": "OC\\Files\\Node\\File",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                "line": 804,
                "function": "OCA\\Richdocuments\\Controller\\{closure}",
                "class": "OCA\\Richdocuments\\Controller\\WopiController",
                "type": "->",
                "args": [
                    "*** sensitive parameters replaced ***"
                ]
            },
            {
                "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                "line": 781,
                "function": "retryOperation",
                "class": "OCA\\Richdocuments\\Controller\\WopiController",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/Files/Lock/LockManager.php",
                "line": 39,
                "function": "OCA\\Richdocuments\\Controller\\{closure}",
                "class": "OCA\\Richdocuments\\Controller\\WopiController",
                "type": "->",
                "args": [
                    "*** sensitive parameters replaced ***"
                ]
            },
            {
                "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                "line": 784,
                "function": "runInScope",
                "class": "OC\\Files\\Lock\\LockManager",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
                "line": 511,
                "function": "wrappedFilesystemOperation",
                "class": "OCA\\Richdocuments\\Controller\\WopiController",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
                "line": 230,
                "function": "putFile",
                "class": "OCA\\Richdocuments\\Controller\\WopiController",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
                "line": 137,
                "function": "executeController",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
                "line": 184,
                "function": "dispatch",
                "class": "OC\\AppFramework\\Http\\Dispatcher",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/lib/private/Route/Router.php",
                "line": 315,
                "function": "main",
                "class": "OC\\AppFramework\\App",
                "type": "::"
            },
            {
                "file": "/var/www/nextcloud/lib/base.php",
                "line": 1069,
                "function": "match",
                "class": "OC\\Route\\Router",
                "type": "->"
            },
            {
                "file": "/var/www/nextcloud/index.php",
                "line": 39,
                "function": "handleRequest",
                "class": "OC",
                "type": "::"
            }
        ],
        "File": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
        "Line": 197
    },
    "message": "Uncaught error: Object of class OC\\User\\LazyUser could not be converted to string in file '/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php' line 197",
    "exception": {},
    "CustomMessage": "Uncaught error: Object of class OC\\User\\LazyUser could not be converted to string in file '/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php' line 197"
}
artonge commented 11 months ago

Ah, forgot to add ->getUID() at the end :see_no_evil:. Sorry, can you try again with this patch?

null_path_files_versions_hook.txt

kyrofa commented 11 months ago

When I disable the version app, the problem is solved.

Thank you for this @jakobroehrl, that's allowing me to actually encrypt files.

SystemKeeper commented 11 months ago

Sorry, can you try again with this patch?

Sure 👍

Here you go:

With "marcel.mueller" being the user who shared the file and "test" the user who tried to edit on an iPhone.

{
    "reqId": "mhRiDveSa3WjEDte4j6D",
    "level": 3,
    "time": "2023-12-14T18:08:41+01:00",
    "remoteAddr": "172.30.150.2",
    "user": "test",
    "app": "files_versions",
    "method": "POST",
    "url": "//index.php/apps/richdocuments/wopi/files/866619_oc4r8rpp6vq8/contents?access_token=...&access_token_ttl=1702609577000",
    "message": "Failed to find relative path for file for /marcel.mueller/files/Gesch\u00e4ftsleitung/SubFolder/File.xlsx and owner test",
    "userAgent": "COOLWSD HTTP Agent 23.05.5.4",
    "version": "28.0.0.11",
    "data": {
        "app": "files_versions"
    }
}
SystemKeeper commented 11 months ago

For testing I moved the logging part to the outside of the if, so it's logged in all cases.

When I log in as user "test" and edit the file in Web, this happens:

{
    "reqId": "lB7HzB0OuD1lzetbfqqW",
    "level": 3,
    "time": "2023-12-14T20:28:36+01:00",
    "remoteAddr": "172.30.150.2",
    "user": "test",
    "app": "files_versions",
    "method": "POST",
    "url": "//index.php/apps/richdocuments/wopi/files/866619_oc4r8rpp6vq8/contents?access_token=....&access_token_ttl=0",
    "message": "Found relative path for file for /test/files/SharedFolder/File.xlsx and owner marcel.mueller",
    "userAgent": "COOLWSD HTTP Agent 23.05.5.4",
    "version": "28.0.0.11",
    "data": {
        "app": "files_versions"
    }
}

When I edit the same file on iOS this happens (still user "test"):

{
    "reqId": "BweWs7paOuwiU9WQRbL2",
    "level": 3,
    "time": "2023-12-14T20:29:11+01:00",
    "remoteAddr": "172.30.150.2",
    "user": "test",
    "app": "files_versions",
    "method": "POST",
    "url": "//index.php/apps/richdocuments/wopi/files/866619_oc4r8rpp6vq8/contents?access_token=....&access_token_ttl=1702618112000&permission=edit",
    "message": "Failed to find relative path for file for /marcel.mueller/files/Gesch\u00e4ftsleitung/SharedFolder/File.xlsx and owner test",
    "userAgent": "COOLWSD HTTP Agent 23.05.5.4",
    "version": "28.0.0.11",
    "data": {
        "app": "files_versions"
    }
}
SystemKeeper commented 11 months ago

Edit web: Bildschirmfoto 2023-12-14 um 21 34 08

Edit iOS: Bildschirmfoto 2023-12-14 um 21 32 14

jakobroehrl commented 11 months ago

I experience this every time a office doc was edited by a mobile app. The mobile call is different to the browser call: https://github.com/nextcloud/server/issues/40090#issuecomment-1750762886 But I do not understand why it does not occur on my AIO installation. Same nc version, same versions app version (version app is enabled)

jakobroehrl commented 11 months ago

Ah, forgot to add ->getUID() at the end 🙈. Sorry, can you try again with this patch?

null_path_files_versions_hook.txt

How can I apply this patch?

artonge commented 10 months ago

Could https://github.com/nextcloud/server/pull/42075 and https://github.com/nextcloud/richdocuments/pull/3340 fix the issue? For 27, the richdocuments part is not yet released, but if one of you updated to 28, the PRs should be included.

SystemKeeper commented 10 months ago

but if one of you updated to 28, the PRs should be included.

My tests above were all made with 28. so I guess this does not fix it ?

artonge commented 10 months ago

My tests above were all made with 28. so I guess this does not fix it ?

Can you check the version of richdocuments?

jakobroehrl commented 10 months ago

Which richdocuments release contains the fix? 8.3.0? https://github.com/nextcloud/richdocuments/releases

https://github.com/nextcloud/richdocuments/pull/3340 is a backport of https://github.com/nextcloud/richdocuments/pull/3330 Is it right, that this requires NC29? https://github.com/nextcloud/server/pull/41944

artonge commented 10 months ago

Yes, 8.3.0 contains the fix. 28 is enough

SystemKeeper commented 10 months ago

Retested on 28.0.1.0 with richdocuments 8.3.0, same error

SystemKeeper commented 10 months ago

I tried to take a look if the problem comes from richdocuments and checked this code part:

https://github.com/nextcloud/richdocuments/blob/4ac2f9379937dd3148b39d8cd3a0726856bf8c46/lib/Controller/WopiController.php#L836-L846

Bildschirmfoto 2023-12-18 um 21 22 57 Bildschirmfoto 2023-12-18 um 21 22 27

As you can see on the left side, the path is already different in the richdocuments app.

$wopi->getUserForFileAccess() returns bob in the working case, and admin in the not working one.

This https://github.com/nextcloud/richdocuments/blob/4ac2f9379937dd3148b39d8cd3a0726856bf8c46/lib/Db/Wopi.php#L163-L165

returns true in the iOS case which returns the ownerUid at https://github.com/nextcloud/richdocuments/blob/4ac2f9379937dd3148b39d8cd3a0726856bf8c46/lib/Db/Wopi.php#L175

iOS has a wopi tokenType of 1, while a browser has a tokenType of 0.

kyrofa commented 10 months ago

I tried to take a look if the problem comes from richdocuments

FYI, I have this issue, and don't have richdocuments.

jakobroehrl commented 10 months ago

Retested on 28.0.1.0 with richdocuments 8.3.0, same error

same on my site

githubkoma commented 10 months ago

Ah, forgot to add ->getUID() at the end 🙈. Sorry, can you try again with this patch?

null_path_files_versions_hook.txt

applying this patch while debugging this error also happening within multiboards app the following log comes up:

{"reqId":"aF19X6Z9SeoNw7KRMfLe","level":3,"time":"2024-01-14T14:03:24+00:00","remoteAddr":"127.0.0.1","user":"user2","app":"files_versions","method":"PUT","url":"/index.php/apps/multiboards/file/save?fileId=null&shareToken=tN9LqDcZ5qcYScD","message":"Failed to find relative path for file for /admin/files/MultiBoard 14 Jan 2024 101608 GMT.mboard and owner admin","userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0","version":"28.0.1.1","data":{"app":"files_versions"}}

thing is it does not happen if the logged in user is the same user who created and shared the file of relevance, it only happens if another NC user is logged in, tries to access the file via sharetoken, and then this error throws..

blizzz commented 10 months ago

I tried to take a look if the problem comes from richdocuments

FYI, I have this issue, and don't have richdocuments.

@kyrofa Would you mind sharing your stack trace, too?

kyrofa commented 10 months ago

Hey @blizzz, already did a ways up.

blizzz commented 10 months ago

Hey @blizzz, already did a ways up.

Uh, sorry, missed that! Thanks!

artonge commented 9 months ago

Hey, could one of you test the following PR: https://github.com/nextcloud/server/pull/42891 ?

SystemKeeper commented 9 months ago

Hey, could one of you test the following PR: #42891 ?

Hey, couldn't test it too much, but a quick test showed no exception and a version being created! Thanks!

githubkoma commented 9 months ago

Hey, could one of you test the following PR: #42891 ?

for me and a quick test it looks like this:

jakobroehrl commented 8 months ago

Fixed for me with the latest NC version, I actived the version App again.

defekT1312 commented 8 months ago

Hey, just want to tell you that I'm having the same Problem, disabling Versions solves the Problem it seems.

I'm on: Versions 1.21.0 NextCloudPi 28.0.3 Backup 1.4.0

No Richdocuments or Office installed.

Please tell me if I can do anything to help you figuring this out.

artonge commented 8 months ago

Please tell me if I can do anything to help you figuring this out.

What could help would be to add the following lines in apps/files_versions/lib/Listener/FileEventsListener.php, right before the last return null;.

$this->logger->error('Failed to find relative path for file for ' . $node->getPath() . ' and owner ' . $node->getOwner()->getUID());

And then to trigger the error again, and to post the generated logs here.

defekT1312 commented 8 months ago

Please tell me if I can do anything to help you figuring this out.

What could help would be to add the following lines in apps/files_versions/lib/Listener/FileEventsListener.php, right before the last return null;.

$this->logger->error('Failed to find relative path for file for ' . $node->getPath() . ' and owner ' . $node->getOwner()->getUID());

And then to trigger the error again, and to post the generated logs here.

I'm sorry, I gave up on the backup app. I was trying for 2 days and I'm tired of this app. Using Borg now, works like a charm.

ClundXIII commented 6 months ago

And then to trigger the error again, and to post the generated logs here.

We have the same issue, latest version of Collabora (coolwsd 24.04.1.4) and Nextcloud v28.0.5:

Failed to find relative path for file for /<user name 1>/files/<group folder>/<file path inside group folder>.docx and owner <user name 2>

user name 1: the user who I presume created the document user name 2: myself when I try to edit the file

SystemKeeper commented 6 months ago

I am also seeing the exception again. Here is the log as requested:

{
    "reqId": "dzYhDuN388vLllOuTTuc",
    "level": 3,
    "time": "2024-05-05T15:19:33+02:00",
    "remoteAddr": "172.30.150.2",
    "user": "test",
    "app": "files_versions",
    "method": "POST",
    "url": "/index.php/apps/richdocuments/wopi/files/..../contents?access_token=....&access_token_ttl=0",
    "message": "Failed to find relative path for file for /marcel.mueller/files/<Folder>/<Subfolder>/2024.xlsx and owner test",
    "userAgent": "COOLWSD HTTP Agent 24.04.1.4",
    "version": "29.0.0.19",
    "data": {
        "app": "files_versions"
    }
}

Notes:

When I add an additional log to the beginning of the getPathForNode function and try the same via the Web (so not iOS), like this:

$this->logger->error('Trying to find relative path for file for ' . $node->getPath() . ' and owner ' . $node->getOwner()->getUID());

I get:

Trying to find relative path for file for /test/files/<Subfolder>/2024.xlsx and owner marcel.mueller

and a version is created (so user and owner are swapped).

What works for me is to still try to get the owner based on the path:

diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php
index 3273f1f9c40..b3254b0e424 100644
--- a/apps/files_versions/lib/Listener/FileEventsListener.php
+++ b/apps/files_versions/lib/Listener/FileEventsListener.php
@@ -403,6 +403,22 @@ class FileEventsListener implements IEventListener {
                        }
                }

+               // Try to get the owner of the file based on the path as a fallback
+               $parts = explode('/', $node->getPath(), 4);
+               if (count($parts) === 4) {
+                       $owner = $parts[1];
+
+                       $path = $this->rootFolder
+                               ->getUserFolder($owner)
+                               ->getRelativePath($node->getPath());
+
+                       if ($path !== null) {
+                               return $path;
+                       }
+               }
+

What I still don't get, why is the user/owner swapped when editing the file on the iOS app in the first place?

SystemKeeper commented 6 months ago

What I still don't get, why is the user/owner swapped when editing the file on the iOS app in the first place?

Judging from https://github.com/nextcloud/server/pull/44294#issuecomment-2042599497 that seems expected.

Also https://github.com/nextcloud/richdocuments/pull/3558 recently changed the user when editing, which could also make a difference here I guess.

@juliushaertl Maybe there’s a better way to get the path in this scenario with Collabora ?

juliusknorr commented 6 months ago

I worked on a better approach for storages that do not have a dedicated owner with https://github.com/nextcloud/server/pull/44294 https://github.com/nextcloud/groupfolders/pull/2872 That way we would no longer need to get the path but could just use the storage provided user id

SystemKeeper commented 2 months ago

@juliushaertl I upgraded to 30 RC, both PRs are included, still I am unable to edit shared richdocuments files. The only way to make it work is to apply the patch I posted at https://github.com/nextcloud/server/issues/40090#issuecomment-2094819016.

Is there still something missing or should it work?

Here's the log:

{
  "Exception": "Exception",
  "Message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 492 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1103",
  "Code": 0,
  "Trace": [
    {
      "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
      "line": 161,
      "function": "dispatch",
      "class": "OC\\AppFramework\\Http\\Dispatcher",
      "type": "->"
    },
    {
      "file": "/var/www/nextcloud/lib/private/Route/Router.php",
      "line": 309,
      "function": "main",
      "class": "OC\\AppFramework\\App",
      "type": "::"
    },
    {
      "file": "/var/www/nextcloud/lib/base.php",
      "line": 996,
      "function": "match",
      "class": "OC\\Route\\Router",
      "type": "->"
    },
    {
      "file": "/var/www/nextcloud/index.php",
      "line": 24,
      "function": "handleRequest",
      "class": "OC",
      "type": "::"
    }
  ],
  "File": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
  "Line": 146,
  "Previous": {
    "Exception": "TypeError",
    "Message": "OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 492",
    "Code": 0,
    "Trace": [
      {
        "file": "/var/www/nextcloud/lib/private/Files/View.php",
        "line": 492,
        "function": "basicOperation",
        "class": "OC\\Files\\View",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/Filesystem.php",
        "line": 516,
        "function": "file_exists",
        "class": "OC\\Files\\View",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/apps/files_versions/lib/Storage.php",
        "line": 158,
        "function": "file_exists",
        "class": "OC\\Files\\Filesystem",
        "type": "::"
      },
      {
        "file": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
        "line": 174,
        "function": "store",
        "class": "OCA\\Files_Versions\\Storage",
        "type": "::"
      },
      {
        "file": "/var/www/nextcloud/apps/files_versions/lib/Listener/FileEventsListener.php",
        "line": 80,
        "function": "write_hook",
        "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/EventDispatcher/ServiceEventListener.php",
        "line": 68,
        "function": "handle",
        "class": "OCA\\Files_Versions\\Listener\\FileEventsListener",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
        "line": 230,
        "function": "__invoke",
        "class": "OC\\EventDispatcher\\ServiceEventListener",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/3rdparty/symfony/event-dispatcher/EventDispatcher.php",
        "line": 59,
        "function": "callListeners",
        "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
        "line": 67,
        "function": "dispatch",
        "class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/EventDispatcher/EventDispatcher.php",
        "line": 79,
        "function": "dispatch",
        "class": "OC\\EventDispatcher\\EventDispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/Node/HookConnector.php",
        "line": 74,
        "function": "dispatchTyped",
        "class": "OC\\EventDispatcher\\EventDispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/legacy/OC_Hook.php",
        "line": 82,
        "function": "write",
        "class": "OC\\Files\\Node\\HookConnector",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/View.php",
        "line": 560,
        "function": "emit",
        "class": "OC_Hook",
        "type": "::"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/View.php",
        "line": 603,
        "function": "emit_file_hooks_pre",
        "class": "OC\\Files\\View",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/Node/File.php",
        "line": 52,
        "function": "file_put_contents",
        "class": "OC\\Files\\View",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
        "line": 467,
        "function": "putContent",
        "class": "OC\\Files\\Node\\File",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
        "line": 756,
        "function": "OCA\\Richdocuments\\Controller\\{closure}",
        "class": "OCA\\Richdocuments\\Controller\\WopiController",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
        "line": 733,
        "function": "retryOperation",
        "class": "OCA\\Richdocuments\\Controller\\WopiController",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/Lock/LockManager.php",
        "line": 68,
        "function": "OCA\\Richdocuments\\Controller\\{closure}",
        "class": "OCA\\Richdocuments\\Controller\\WopiController",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
        "line": 736,
        "function": "runInScope",
        "class": "OC\\Files\\Lock\\LockManager",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/apps/richdocuments/lib/Controller/WopiController.php",
        "line": 466,
        "function": "wrappedFilesystemOperation",
        "class": "OCA\\Richdocuments\\Controller\\WopiController",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 208,
        "function": "putFile",
        "class": "OCA\\Richdocuments\\Controller\\WopiController",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 114,
        "function": "executeController",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
        "line": 161,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Route/Router.php",
        "line": 309,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::"
      },
      {
        "file": "/var/www/nextcloud/lib/base.php",
        "line": 996,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/index.php",
        "line": 24,
        "function": "handleRequest",
        "class": "OC",
        "type": "::"
      }
    ],
    "File": "/var/www/nextcloud/lib/private/Files/View.php",
    "Line": 1103
  },
  "message": "Uncaught error: OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 492 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1103",
  "exception": {},
  "CustomMessage": "Uncaught error: OC\\Files\\View::basicOperation(): Argument #2 ($path) must be of type string, null given, called in /var/www/nextcloud/lib/private/Files/View.php on line 492 in file '/var/www/nextcloud/lib/private/Files/View.php' line 1103"
}
juliusknorr commented 2 months ago

Indeed, i could reproduce that, could you check the patch in https://github.com/nextcloud/richdocuments/pull/3948 and see if that does the trick for you?