Skip to content

fix(Node): Do not drop readonly attributes but only forbid updating them - #967

Merged
susnux merged 2 commits into
mainfrom
fix/do-not-remove-attributes
May 29, 2024
Merged

fix(Node): Do not drop readonly attributes but only forbid updating them#967
susnux merged 2 commits into
mainfrom
fix/do-not-remove-attributes

Conversation

@susnux

@susnux susnux commented May 29, 2024

Copy link
Copy Markdown
Contributor

Attributes that are readonly should still be listed in the attributes getter, otherwise this is a hard breaking change as a lot of apps already depend on attributes. So instead only ensure that readonly attributes are skipped by the proxy handler.

@susnux susnux added type: bug 🐛 Something isn't working 3. to review 3️⃣ Waiting for reviews labels May 29, 2024
@susnux
susnux requested review from ShGKme and skjnldsv May 29, 2024 08:08
@codecov

codecov Bot commented May 29, 2024

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 1.97kB ⬆️

Bundle name Size Change
@nextcloud/files-esm 109.83kB 987 bytes ⬆️
@nextcloud/files-esm-cjs 110.86kB 110.86kB ⬆️
@nextcloud/files-cjs (removed) 109.87kB ⬇️

@susnux

susnux commented May 29, 2024

Copy link
Copy Markdown
Contributor Author

See error when upgrading files on server (and we need to backport to 29 and 28!):
nextcloud/server#45538

Attributes that are readonly should still be listed in the `attributes` getter,
otherwise this is a hard breaking change as a lot of apps already depend on `attributes`.
So instead only ensure that readonly attributes are skipped by the proxy handler.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux
susnux force-pushed the fix/do-not-remove-attributes branch from 13eb986 to 4a7ece4 Compare May 29, 2024 08:24
@susnux
susnux requested review from Pytal and artonge May 29, 2024 10:52

@skjnldsv skjnldsv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, why do you use the attributes.size ?
That is the issue in the first place, no?

@susnux

susnux commented May 29, 2024

Copy link
Copy Markdown
Contributor Author

I disagree, why do you use the attributes.size ?
That is the issue in the first place, no?

It was never documented to not use attributes for size or basename so removing them from attributes breaks the API.
So removing attributes was a breaking change that needs to be reverted or like here to be fixed.

We can branch off if you like and spin up a new major for the removed attributes, but I think in general it makes more sense to keep the attributes and just make them readonly (like I did here).

@susnux
susnux force-pushed the fix/do-not-remove-attributes branch 2 times, most recently from f1142dc to f11ad8c Compare May 29, 2024 16:36
…gh Node.attributes

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux
susnux force-pushed the fix/do-not-remove-attributes branch from f11ad8c to 12b6dcc Compare May 29, 2024 16:46
@susnux

susnux commented May 29, 2024

Copy link
Copy Markdown
Contributor Author

Added a test case to prevent doing:

file.attributes.owner = 'foo'

As this is also protected

@susnux
susnux merged commit b32e636 into main May 29, 2024
@susnux
susnux deleted the fix/do-not-remove-attributes branch May 29, 2024 16:48
Comment thread lib/files/node.ts
Comment on lines +358 to +371
for (const [name, value] of Object.entries(attributes)) {
try {
if (value === undefined) {
delete this.attributes[name]
} else {
this.attributes[name] = value
}
} catch (e) {
// Ignore readonly attributes
if (e instanceof TypeError) {
continue
}
// Throw all other exceptions
throw e

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One drawback of this, now there is no way to update ll attributes without updating the mtime :/
That was one of the feature I added and needed from #947 😅 @susnux

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you can't remove attributes anymore (unless you know they exist on the node already)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review 3️⃣ Waiting for reviews type: bug 🐛 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants