Native attribute for files?
I've added a feature, that the Shelly adapter downloads all scripts to the file section of ioBroker. The idea is, that the user can edit the file and ioBroker will send the modified script back to the Shelly (if changed).
All scripts have their own ID and a name. At the moment, I use the script name as file name. But I have no idea which script belongs to which ID. For objects, I can use a native attribute to store that information. But not for files. I need something like
await this.writeFileAsync(this.namespace, `${scriptDir}/${script.name}.js`, scriptCode.data, {id: script.id});
Any suggestion?
Files are just files like in the File system ... you can not extend that by any information and I'm not sure if this would not bring unneeded compexity in the whole file topic ... I would see such a mapping vise-versa ... so in adapter you know which script belongs to what.
Any reason you can't put the ID into the filename too?
Files are just files like in the File system ... you can not extend that by any information
It depends. Some file systems support meta information on files (like tags). And we already have the meta storage for file size and permissions.
Any reason you can't put the ID into the filename too?
I can - but I want to discuss that topic because it is a common feature for objects.
I think adding an object for a file and holding this in sync adds a lot of complexity, and with nly this usecase it is not ebough use cases in my eyes.
So only way would be "enhancing the stored meta data with additional user-defined details" - but this is not that straight forward when I remember the code correctly and could easiely be lost when meta files are hard regenerated (because would require to merge it ;-( And we would also need to store the meta data on backup (do we do that currently, good question ?)
For your challenge: I would go with "store the ID as first line of the script as kind of a comment line ... easy to parse out afterwards ...
So only way would be "enhancing the stored meta data with additional user-defined details"
That was the idea of this issue. Since the directory already contains a folder with some meta information, I thought it isn't that complicate to add more information there. It was just an idea - we can close this issue 👍
Let's keep open for now, lets see ... in fact first of all we need to make sure the backup is storing the meta data (or at least relevant parts of it) "at all" /(we found that out while checking because of this idea)
But in fact I assume it is nothign for js.controller 4.1 :-)