Commit Graph

254 Commits

Author SHA1 Message Date
Robin Appelman cb51564356 trigger a rescan when trying to fopen a file that exists in cache but not on disk
Signed-off-by: Robin Appelman <robin@icewind.nl>
2022-09-29 11:17:16 +02:00
Vincent Petry 1025d049c7
Merge pull request #24596 from kofemann/dcache-worm
make NextCloud WORM file system friendly
2022-09-16 14:39:13 +02:00
Tigran Mkrtchyan f41209a061 config: add a switch to control truncate before update
To avoid extra truncate on non WORM file systems, add a new config
option `localstorage.unlink_on_truncate`, which defaults to false.

The OC\Files\Storage\Local is update to respect that option.

Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
2022-09-16 11:10:32 +02:00
Tigran Mkrtchyan 8fc4cf67f1 files: remove destination file before copying new content (WORM)
Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
2022-09-16 10:57:17 +02:00
Git'Fellow 5300f0d693
Switch logical operators (and|or)
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
2022-09-12 09:35:12 +02:00
Robin Appelman bd91c56539
get quota for user only when needed
always apply the wrapper but have the wrapper get the quota lazily only when an operation where quota is applied is performed

Signed-off-by: Robin Appelman <robin@icewind.nl>
2022-09-01 19:32:24 +02:00
Tigran Mkrtchyan b6065a236f files: make OC\Files\Storage\Local WORM friendly
Some filesystems run as a Write-Once-Read-Many storages. This
makes them impossible to use with NexeCloud, as the file system
layers uses `truncate` syscall (through file_put_contents function).

As Nextcloud is never updates existing files, removing the old entry
and creatint a new one on update will allow NextCoud to update on such
file systems.

Update Local#fopen and Local#file_put_contents to remote existing
file before truncating.

Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
2022-08-25 11:11:49 +02:00
Carl Schwan d5c23dbb9f Move CappedMemoryCache to OCP
This is an helpful helper that should be used in more place than just
server and this is already the case with groupfodlers, deck, user_oidc
and more using it, so let's make it public

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
2022-07-14 15:54:31 +02:00
blizzz 2e10378052
Merge pull request #31475 from nextcloud/kofemann-patch-1
files: close open directory file descriptor on error path
2022-06-21 18:44:05 +02:00
Vincent Petry 8809de1eef
Merge pull request #31966 from nextcloud/unencrypted-size
store unencrypted size in the unencrypted_size column
2022-06-13 11:55:37 +02:00
Martin Brugnara 7409569994
Expose umask override value as config parameter: localstorage.umask
Commit 451c06d introduced override for umask value.
This is needed to avoid broken env configuration or dirty workers
to mess with the permissions when creating new files.

Most Nextcloud, that does not integrate with external software
would work fine with an hard-coded value (451c06d set it at 022).

Advanced install may require more flexibility, as such this commit
exposes the "umask override value" as configuration parameter:
`localstorage.umask`

It defaults to 0022 both in code and in config/config.sample.php .

Signed-off-by: Martin Brugnara <martin@0x6d62.eu>
2022-06-05 19:19:31 +02:00
Robin Appelman 8238582e59
store unencrypted size in the unencrypted_size column
Signed-off-by: Robin Appelman <robin@icewind.nl>
2022-06-02 16:07:00 +02:00
Côme Chilliet 2b07031d3e
composer run cs:fix
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2022-04-26 16:52:53 +02:00
Côme Chilliet 23f7a37c03
Remove ILogger usages in lib/private/Files/Storage
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2022-04-26 16:52:53 +02:00
Robin Appelman 468d6a9cf1
ignore forbidden files while scanning local storage
Signed-off-by: Robin Appelman <robin@icewind.nl>
2022-04-20 13:01:16 +02:00
Robin Appelman f9a5fb99fd
use the same cached propfind for free space for dav storage
Signed-off-by: Robin Appelman <robin@icewind.nl>
2022-04-04 16:48:31 +02:00
Louis 7d2cb35988
Merge pull request #31632 from Maaxxs/fix-undefined-index-dav
Fixes the undefined index error with the DAV property getlastmodified
2022-03-29 13:53:15 +02:00
Max Kunzelmann 2952c7d01f Use the null coalescing operator to set the value of `size`.
Signed-off-by: Max Kunzelmann <maxdev@posteo.de>
2022-03-28 22:26:45 +02:00
Côme Chilliet e8c1f75064
Fixing psalm errors
Encryption constructor is problematic and should still be fixed later.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2022-03-24 16:21:26 +01:00
Côme Chilliet 6be7aa112f
Migrate from ILogger to LoggerInterface in lib/private
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2022-03-24 16:21:25 +01:00
Max Kunzelmann 3a135f0c5f Set `mtime` to null instead of false if `getlastmodified` does not exist.
Signed-off-by: Max Kunzelmann <maxdev@posteo.de>
2022-03-23 15:02:01 +01:00
Max Kunzelmann e0a5fe649a Fix typo.
Signed-off-by: Max Kunzelmann <maxdev@posteo.de>
2022-03-20 11:07:36 +01:00
Max Kunzelmann ee888875bb Fixes the undefined index error with the DAV property getlastmodified
Signed-off-by: Max Kunzelmann <maxdev@posteo.de>
2022-03-20 00:38:07 +01:00
Robin Appelman 84f464550a
some file scanner performance improvements
Signed-off-by: Robin Appelman <robin@icewind.nl>
2022-03-17 22:21:16 +01:00
Tiramisu Mokka 8190441335
files: close open directory file descriptor on error path 2022-03-07 10:19:58 +01:00
Côme Chilliet 5cca86ce19
Remove redundant if clause
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2022-01-25 16:53:35 +01:00
Côme Chilliet 35dcda36a3
Fix OC\Files\Storage\DAV::hasUpdated when cache is not set
Fixes the test OCA\Files_External\Tests\Storage\WebdavTest::testStat on
 PHP>=7.4

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2022-01-25 16:53:19 +01:00
Vincent Petry cfafd79706
Merge pull request #30631 from nextcloud/fix/update_encrypted_version
updateEncryptedVersion: cleanup on target if cache already got renamed
2022-01-14 09:45:08 +01:00
Carl Schwan cbf9064b8e
Fix psalm issues
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
2022-01-13 12:30:27 +01:00
Carl Schwan 695165260f
Add helper method in Wrapper
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
2022-01-13 10:39:36 +01:00
Jonas Meurer a2f4c62c19
updateEncryptedVersion: cleanup on target if cache already got renamed
When moving a file to trash with encryption enabled, the cache gets
moved before the actual file. According to @icewind1991 this is in order
to not break object storage.

When moving a file from an unencrypted storage (e.g. a collectives
storage) to the encrypted trashbin storage, this causes errors, see

This commit fixes it by doing `updateEncryptedVersion()` on the target
cache entry *if* the source cache entry doesn't exist anymore, but the
corresponding target cache entry does exist already.

Fixes: #26544

Signed-off-by: Jonas Meurer <jonas@freesources.org>
2022-01-12 15:47:08 +01:00
Vincent Petry be590df588
Fix fail when keys/files folder already exists
Fixes an issue with transfer ownership in move mode where the folder
"files_encryption/keys/files" already exists.

Instead of failing, its existence is checked before calling mkdir.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
2022-01-10 11:15:22 +01:00
Vincent Petry 6f81e60bce
Check resource before closing in encryption wrapper
In case of error there is no guarantee that $source or $target is set or
is a resource when handling an error.

Without this fix, there's a risk that fclose will fail and the actual
exception will not be thrown, making it impossible to find out about the
root cause.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
2021-12-09 11:28:10 +01:00
Joas Schilling 65d79bb592
Check for invalid characters before trimming
Signed-off-by: Joas Schilling <coding@schilljs.com>
2021-11-25 08:48:26 +01:00
Vincent Petry 289624b79e
Merge pull request #29758 from nextcloud/disk_free_space-fix-php8
Check for `disk_free_space`
2021-11-19 17:14:08 +01:00
acsfer 152e2bfdaa
Check for `disk_free_space`
Check for `disk_free_space` before calling it.
Fix https://github.com/nextcloud/server/issues/29748
2021-11-18 11:46:13 +01:00
Vincent Petry c92a0e4152
Normalize directory entries in Encoding wrapper
Directory entry file names are now normalized in getMetaData(),
getDirectoryContents() and opendir().

This makes the scanner work properly as it assumes pre-normalized names.

In case the names were not normalized, the scanner will now skip the
entries and display a warning when applicable.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
2021-11-17 09:43:25 +01:00
Vincent Petry 93fb33d863
Update lib/private/Files/Storage/Wrapper/Availability.php add void
Signed-off-by: Vincent Petry <vincent@nextcloud.com>

Co-authored-by: Carl Schwan <carl@carlschwan.eu>
2021-11-05 10:28:41 +01:00
Vincent Petry db29fd29ee
Return false in hasUpdated when storage is not available
Technically, saying that a storage has no updates when it's not
available is correct.

This makes it possible to retrieve the cache entry for the mount point
and also to list and remove unavailable federated shares.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
2021-11-05 09:48:52 +01:00
alanmeeson 16f70e8647 Add type hint to fread_block $blockSize param & apply cs:fix.
Signed-off-by: alanmeeson <alan@carefullycalculated.co.uk>
2021-10-23 15:11:23 +01:00
Alan Meeson 44c332a46e Fix truncation of files upon read when using object store and encryption.
When using and object store as primary storage and using the default
encryption module at the same time,  any encrypted file would be truncated
when read, and a text error message added to the end.

This was caused by a combination of the reliance of the read functions on
on knowing the unencrypted file size,  and a bug in the function which
calculated the unencrypted file size for a given file.

In order to calculate the unencrypted file size,  the function would first
skip the header block, then use fseek to skip to the last encrypted block
in the file.  Because there was a corresponence between the encrypted and
unencrypted blocks, this would also be the last encrypted block.  It would
then read the final block and decrypt it to get the unencrypted length of
the last block.  With that, the number of blocks, and the unencrypted block
size, it could calculate the unencrypted file size.

The trouble was that when using an object store, an fread call doesn't
always get you the number of bytes you asked for, even if they are
available.  To resolve this I adapted the stream_read_block function from
lib/private/Files/Streams/Encryption.php to work here.  This function
wraps the fread call in a loop and repeats until it has the entire set of
bytes that were requested,  or there are no more to get.

This fixes the imediate bug, and should (with luck) allow people to get
their encrypted files out of Nextcloud now.  (The problem was purely on
the decryption side).  In the future it would be nice to do some
refactoring here.

I have tested this with image files ranging from 1kb to 10mb using
Nextcloud version 22.1.0 (the nextcloud:22.1-apache docker image), with
sqlite and a Linode object store as the primary storage.

Signed-off-by: Alan Meeson <alan@carefullycalculated.co.uk>
2021-10-23 15:11:23 +01:00
John Molakvoæ f4e4a85fcf
Merge pull request #27440 from nextcloud/is-file-handle 2021-10-23 11:18:52 +02:00
John Molakvoæ e673ec0b87
Merge branch 'master' into imountpoint-ocp-storage 2021-10-22 11:47:37 +02:00
Carl Schwan 9408f8ae69
Fix security issues when copying groupfolder with advanced ACL
Using advanced ACL, it is possible that an user has access to a
directory but not to a subdirectory, so the copying use
Common::copyFromStorage instead of Local::copyFromStorage.

Fix https://github.com/nextcloud/groupfolders/issues/1692

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
2021-10-21 17:11:52 +02:00
John Molakvoæ a1c8b6e9eb
Merge pull request #28768 from nextcloud/check-file-exists 2021-10-18 09:54:22 +02:00
John Molakvoæ 739b67031b
Merge pull request #27194 from nextcloud/new-ftp 2021-10-14 10:29:24 +02:00
Robin Appelman b3766fc99b
make param names consistent with interface for copy directory polyfill
Signed-off-by: Robin Appelman <robin@icewind.nl>
2021-10-07 17:19:44 +02:00
acsfer 98eac0fc05
Simplify :) 2021-10-04 17:21:37 +02:00
acsfer 8a8df49bc0
Replace `file_exists()` method by `is_file()` 2021-10-04 17:20:17 +02:00
acsfer 3a25183b66 Get `filesize()` if `file_exists()`
Should make sense.
2021-10-01 21:02:38 +00:00