nextcloud / nextcloud/server

[Bug]: "Tried to create an object store folder that already exists" warning with empty path on every account creation

Open Beginner friendly
#63,888 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. Needs triage 34-feedback bug feature: object storage
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

⚠️ This issue respects the following points: ⚠️
  • This is a bug, not a question or a configuration/webserver/proxy issue.
  • This issue is not already reported on Github (I've searched it).
  • Nextcloud Server is up to date.
  • I agree to follow Nextcloud's Code of Conduct.
Bug description

On an instance with primary object storage, every account creation logs a warning that renders with an empty path:

Tried to create an object store folder that already exists: 

The trailing value is empty because the path is the storage root ('').

It is harmless — the root exists afterwards, which is the desired end state — but it is logged at warning level, it fires deterministically, and the message reads as though something is wrong. On instances that create accounts in bulk (provisioning scripts, LDAP/SSO first logins) it is pure noise at a severity that gets alerted on.

Cause

SetupManager::setupForUser() creates the home storage root when it believes the root is not yet in the cache:

https://github.com/nextcloud/server/blob/v34.0.3/lib/private/Files/SetupManager.php#L333-L337

if ($homeMount->getStorageRootId() === -1) {
    $homeMount->getStorage()->mkdir('');          // <-- $force defaults to false
    $homeMount->getStorage()->getScanner()->scan('');
}

ObjectStoreStorage::mkdir() warns whenever the target already exists and $force is not set:

https://github.com/nextcloud/server/blob/v34.0.3/lib/private/Files/ObjectStore/ObjectStoreStorage.php#L81-L86

public function mkdir(string $path, bool $force = false, array $metadata = []): bool {
    $path = $this->normalizePath($path);
    if (!$force && $this->file_exists($path)) {
        $this->logger->warning("Tried to create an object store folder that already exists: $path");
        return false;
    }

But the same class also creates the root implicitly, with $force = true, whenever metadata for '' is requested and the cache has no entry:

https://github.com/nextcloud/server/blob/v34.0.3/lib/private/Files/ObjectStore/ObjectStoreStorage.php#L232-L240

if ($path === '') {
    $this->mkdir('', true);

So the root gets created on the fly by the lazy path, and the explicit mkdir('') in SetupManager then warns about a folder the storage created itself moments earlier. The two paths disagree about $force.

Note this is object-store specific: ObjectStoreStorage is the only class that emits this message, so instances on local storage never see it.

Steps to reproduce
  1. Configure an instance with primary object storage (reproduced on S3; the code path is backend-agnostic).
  2. Run occ user:add --password-from-env someuser.
  3. Look in nextcloud.log.
Expected behaviour

No warning. Either the root already exists — which is fine and is what the caller wanted — or it gets created.

Actual behaviour

One warning-level entry per account created:

{"level":2,"app":"no app in context","scriptName":"occ",
 "message":"Tried to create an object store folder that already exists: ",
 "version":"34.0.3.2","occ_command":["occ","user:add"]}

Verified deterministic: the occurrence count in nextcloud.log increases by exactly one per occ user:add.

Suggested fix

Don't warn for the storage root in ObjectStoreStorage::mkdir(). $path === '' already existing is never an error — the storage creates that root itself, with $force = true, in getMetaData().

Passing force at the call site instead would not work: IStorage::mkdir() declares a single parameter

public function mkdir(string $path);

so $homeMount->getStorage()->mkdir('', true) would pass an argument the interface does not have. $force and $metadata exist only on the ObjectStoreStorage implementation, and SetupManager holds an IStorage.

As a separate nit, the message should quote the path, so an empty one is not silently invisible in the log.

Nextcloud Server version

34.0.3

Which database are you using?

mysql (MariaDB 11.6)

Are you using an external user backend?

No

Additional info

Primary storage is \OC\Files\ObjectStore\S3, single bucket. mkdir() returns false in this case; nothing appears to treat that as fatal, so the impact is log noise rather than broken behaviour.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/private/Files/ObjectStore/ObjectStoreStorage.php, then compare the root-creation call from lib/private/Files/SetupManager.php. Reproduce with occ user:add on primary object storage and inspect nextcloud.log; done means account creation no longer emits the empty-path warning while the root remains available.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.