-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(persist): Using [Array] to persist file #3209
Conversation
I would rather see implementation as descibed in #2897 (comment) with small tweak, that content property on file would be array or string |
Sorry, but I would like to use a more complex object instead of an array. I have posted an example on another persistent topic (but I don't know which one right now) "persist": [
{
"type": "file",
"name": "settings.ini",
"content": "blah",
"encoding": "UTF-8"
}
] Sorry I am on mobile right now Edit: @Ash258 is one step ahead of me, as always 😁 Sent from my OnePlus5T using FastHub |
@r15ch13 I already mentioned your post |
Yes, file contents could be array, please see fifth file example above. The function treats all lines except the first two as file contents. The ideal one is perfect, but it means totally rewriting of persist function and is not backward compatible. That's a long time job. This one doesn't change anything with existing manifests, and can be a temporary solution. It could handle most persisting job with just small change. |
It could be backward compatible. Just keep current functionality and add check if it's just object or string. If string apply current implementation. If it's object, apply new one. This will provide time for maintaners to reflect new changes and everything will work. Then after few weeks / months old implementation could be removed. |
You're right, we chould even use script to convert But why not use this one as backward compatible implementation while the new one is under construction? This COULD do most persisting job well now. |
Because you will make update to reflect these changes and then update manifest to adopt future new changes. It's not worth it's time. |
In my opinion, the procedure should be:
Maybe the same thing is leting maintainer change their manifests to adopt new |
Your implementation is not backward compatible, it breaks all manifests which have file-type data persistence. The implementation forces maintainers to update all these manifests to reflect your implementation. diff --git a/shadowsocks.json b/shadowsocks.json
index 72bb2b3..346bb32 100644
--- a/shadowsocks.json
+++ b/shadowsocks.json
@@ -13,10 +13,10 @@
]
],
"persist": [
- "gui-config.json",
- "statistics-config.json",
- "pac.txt",
- "user-rule.txt"
+ ["gui-config.json"],
+ ["statistics-config.json"],
+ ["pac.txt"],
+ ["user-rule.txt"]
], It's not a smooth transition for maintainers and users, which could be a debatable idea I think. Though I don't like this actual implementation, I would do a careful review if you are willing to make it be backward compatible, which means no manifest update needed after adopting your change. |
Proposed schema change: "persist": {
"anyOf": [
{
"type": "string",
"description": "Deprecated, use object representation instead."
},
{
"items": {
"$ref": "#/definitions/stringOrArrayOfStrings"
},
"minItems": 1,
"type": "array",
"description": "Deprecated, use object representation instead."
},
{
"minItems": 1,
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": [
"name",
"type"
],
"if": {
"properties": {
"type": {
"const": "file"
}
}
},
"then": {
"required": [
"encoding",
"content"
]
},
"properties": {
"name": {
"type": "string"
},
"target": {
"type": "string"
},
"type": {
"enum": [
"file",
"directory",
"folder"
]
},
"encoding": {
"enum": [
"utf-8",
"ascii",
"byte"
]
},
"content": {
"$ref": "#/definitions/stringOrArrayOfStrings"
},
"method": {
"enum": [
"copy",
"merge",
"link",
"update"
]
}
}
}
}
]
}, |
@r15ch13 Will you open PR with these changes to schema? To move discussion there. |
Thanks @h404bi. In fact it is backward compatible, since now we create file in I'll use |
@r15ch13 Thanks for the schema, and I'll construct a new implementation on it in few days and an automatical conversion script for it. BTW, I'm not sure what does "merge" mean. For example, if an app persists its |
Alternative #3209 |
|
Close #3210. Add |
I've done the job, now both [Object] and [Array] are supported, please test and review. BTW: I'll open a new PR for clear discussion, and attemp to add conversion script. |
A new way to handle persist data, esp. with files
With this patch, one can distinguish file and dir in
persist
property by the following code:persist
accepts[Array]
as persist object, and array length is checked to determine if it is file or dir, with the following logic:""
, not$null
)\r\n
if persist object is
[String]
, it is dir without change.In persisted file contents, every variables that can be used in
installer.script
can be used, e.g.,$persist_dir
,$architecture
, etc.It is ready to test and be merged, and I made a modified manifest ofnvm.json
for testing.