Skip to content
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

Allow deleteTiddler to not modify fs #6047

Merged
merged 3 commits into from
Mar 3, 2023
Merged

Conversation

linonetwo
Copy link
Contributor

When writing watch-fs plugin that monitor fs change, I found it difficult to handle delete, file delete can happened by calling deleteTiddler, or can be delete by the user using VSCode.

So I need this new option to ask it to not touch fs.

@linonetwo linonetwo changed the title feat: allow deleteTiddler to not modify fs Allow deleteTiddler to not modify fs Sep 18, 2021
Copy link
Member

@Jermolene Jermolene left a comment

Choose a reason for hiding this comment

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

Thanks @linonetwo

@@ -82,20 +82,20 @@ FileSystemAdaptor.prototype.saveTiddler = function(tiddler,callback,options) {
if(err) {
return callback(err);
}
$tw.utils.saveTiddlerToFile(tiddler,fileInfo,function(err,fileInfo) {
$tw.utils.saveTiddlerToFile(tiddler,fileInfo, (err,fileInfo) => {
Copy link
Member

Choose a reason for hiding this comment

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

I'm afraid we can't use arrow functions in the core. We stick to ES5.1 (roughly) because it's important to retain compatibility with older browsers/JS runtimes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will keep that in mind in the following PRs.

@@ -122,14 +122,22 @@ FileSystemAdaptor.prototype.loadTiddler = function(title,callback) {
};

/*
Delete a tiddler and invoke the callback with (err)
Delete a tiddler and invoke the callback with (err)
@params title title of tiddler to delete
Copy link
Member

Choose a reason for hiding this comment

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

We don't use jsdoc style comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can there be a post in Github Discussion talking about this? Currently $tw API doc is incomplete, which makes there being some obstacles in plugin development.

// Only delete the tiddler if we have writable information for the file
var cacheOnly = options.cacheOnly || false;
if(cacheOnly) {
Copy link
Member

Choose a reason for hiding this comment

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

The "cacheOnly" flag isn't used by the core, so I assume it is intended for plugins? It seems like it would be simpler if it was a separate method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, refactor complete!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feel free to point out if you don't like the function name. I think code review is a good place that let people know more about owner's style.

@joshuafontany
Copy link
Contributor

@Jermolene @linonetwo Looking over existing file-system issues. This caught my eye. I feel that this is actually a file-system-permissions issue. I did many tests with loading tiddlers from "read-only" files, and what happens when TW Node tries to delete them as one of my "fail gracefully" tests.

At this point, there is no way for the TW Node server to set specific file permissions, so that would need to be done outside of TW code for the moment (or manually/on the command line). TW code like that leads into needing an "admin" authorization level to the server-flow, which I have started work on.

Good issue! Definitely worth investigating user-facing solutions.

@linonetwo
Copy link
Contributor Author

linonetwo commented Mar 3, 2023

@Jermolene Can you reconsider this? Just add a new method to allow plugin touch file cache.

Just a refactor. No feature change in the core.

Copy link
Member

@Jermolene Jermolene left a comment

Choose a reason for hiding this comment

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

Looks good thanks @linonetwo

@Jermolene Jermolene merged commit d14e775 into TiddlyWiki:master Mar 3, 2023
Jermolene added a commit that referenced this pull request Mar 5, 2023
@linonetwo I realised on review that we refer to boot.files as the "tiddler file info"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants