nextcloud / nextcloud/desktop

[Bug]: Re-enabling sync for large-folder exclusions can overwrite newer server files

Open
#9,316 0 comments 0 reactions 0 assignees View on GitHub
0. Needs triage bug
Dominant language
C++
Stars
3.9k
Forks
1k
Avg merge
1d 17h
Merged PRs (30d)
123

Description

### ⚠️ Before submitting, please verify the following: ⚠️

- [x] This is a **bug**, not a question or a configuration issue.
- [x] This issue is **not** already reported on Github (I've searched it).
- [x] Nextcloud Server and Desktop Client are **up to date**. See [Server Maintenance and Release Schedule](https://github.com/nextcloud/server/wiki/Maintenance-and-Release-Schedule) and [Desktop Releases](https://nextcloud.com/install/#install-clients) for supported versions.
- [x] I agree to follow Nextcloud's [Code of Conduct](https://nextcloud.com/contribute/code-of-conduct/)

### Bug description

We use Nextcloud Desktop Client on macOS (no Virtual Files). A folder was not being synced because of the client setting that asks for confirmation before syncing/downloading folders larger than a configured threshold (500 MB). The folder had synced up to a certain point, then it stopped syncing (user did not realize immediately).

Later, we re-enabled syncing for that folder (“sync everything” / re-check folder). After re-enabling, the client uploaded an **older local copy** of an XLSX file and **overwrote a newer server version** of the same file. No “conflicted copy” was created on the client. The overwritten content is visible in Nextcloud file versions.

This is dangerous because users assume that re-enabling a previously excluded folder will not silently replace newer server data with stale local data.

### Steps to reproduce

We were unable to reproduce this behavior using the macOS desktop client version 4.0.4. When a folder exceeded the configured 500 MB size threshold after initial synchronization, the client did not stop syncing the folder and continued to synchronize its contents.

### Expected behavior

- When re-enabling sync for a folder that has been excluded/not synced for some time, the client should:
- detect that the server file changed since the last known synced state, and
- create a **conflicted copy** (or otherwise avoid overwriting), OR
- download server changes first and require explicit user confirmation before any overwrite.

### Which files are affected by this bug

none

### Operating system

macOS

### Which version of the operating system you are running.

15.7.3

### Package

Official macOS 12+ universal pkg

### Nextcloud Server version

31.0.7

### Nextcloud Desktop Client version

4.0.4

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

Updated from a minor version (ex. 3.16.1 to 3.16.2)

### Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

### Are you using an external user-backend?

- [ ] Default internal user-backend
- [x] LDAP/ Active Directory
- [ ] SSO - SAML
- [ ] Other

### Nextcloud Server logs

```shell
{
"reqId": "REQID_REDACTED_001",
"level": 2,
"time": "2026-01-07T09:29:36+00:00",
"remoteAddr": "192.0.2.56",
"user": "USER_UUID_REDACTED",
"app": "files_versions",
"method": "PUT",
"url": "/nextcloud/remote.php/dav/files/USER_UUID_REDACTED/PROJECT%20team%20-%20LEGACY/2_Team%20admin%20&%20coordination/1_Resource%20planning/RP%20PROJECT%202025%20Oct-Dec.xlsx",
"message": "Constraint violation while inserting version, retrying with increased timestamp",
"userAgent": "Mozilla/5.0 (Macintosh) mirall/4.0.4 (Nextcloud, macos-24.6.0 ClientArchitecture: arm64 OsArchitecture: arm64)",
"version": "31.0.7.1",
"clientReqId": "CLIENTREQID_REDACTED_001",
"exception": {
"Exception": "OC\\DB\\Exceptions\\DbalException",
"Message": "An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'FILEID_REDACTED-1767345944' for key 'files_versions_uniq_index'",
"Code": 1062,
"Trace": [
{
"file": "/var/www/html/nextcloud/lib/private/DB/ConnectionAdapter.php",
"line": 69,
"function": "wrap",
"class": "OC\\DB\\Exceptions\\DbalException",
"type": "::"
},
{
"file": "/var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php",
"line": 306,
"function": "executeStatement",
"class": "OC\\DB\\ConnectionAdapter",
"type": "->"
},
{
"file": "/var/www/html/nextcloud/lib/public/AppFramework/Db/QBMapper.php",
"line": 116,
"function": "executeStatement",
"class": "OC\\DB\\QueryBuilder\\QueryBuilder",
"type": "->"
},
{
"file": "/var/www/html/nextcloud/apps/files_versions/lib/Versions/LegacyVersionsBackend.php",
"line": 239,
"function": "insert",
"class": "OCP\\AppFramework\\Db\\QBMapper",
"type": "->"
},
{
"file": "/var/www/html/nextcloud/apps/files_versions/lib/Versions/VersionManager.php",
"line": 122,
"function": "createVersionEntity",
"class": "OCA\\Files_Versions\\Versions\\LegacyVersionsBackend",
"type": "->",
"args": ["*** sensitive parameters replaced ***"]
}
// ... remaining stack trace unchanged ...
],
"File": "/var/www/html/nextcloud/lib/private/DB/Exceptions/DbalException.php",
"Line": 56,
"Previous": {
"Exception": "Doctrine\\DBAL\\Exception\\UniqueConstraintViolationException",
"Message": "An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'FILEID_REDACTED-1767345944' for key 'files_versions_uniq_index'",
"Code": 1062
// ... remaining nested exceptions unchanged ...
},
"message": "Constraint violation while inserting version, retrying with increased timestamp",
"exception": {
"query": "INSERT INTO *PREFIX*files_versions (file_id, timestamp, size, mimetype, metadata) VALUES(:dcValue1, :dcValue2, :dcValue3, :dcValue4, :dcValue5)"
},
"CustomMessage": "Constraint violation while inserting version, retrying with increased timestamp"
}
}
```

### Additional info

Image

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.