Please delete only playground files...
tevino opened this issue ยท 12 comments
Here is what just happened:
I called go-playground-rm
when I'm working on an regular file accidentally(it's the last command I just run), and the whole directory containing this file was deleted, without confirmation...
what a pity...
Well it is usability issue. I made this command especially for fast deletion. You do experiments with the temporary code then copy paste results to you main codebase and just drop code of the experiment. So if you place some kind of data to the snippet dir I think it the temporary place that should not be persistent. May be add optional confirmation (setup through variable). Or confirmation should appear in case when non go-files found in the snippet dir.
I just clarified note in the playground buffer:
Remove the snippet completely with its dir and all files M-x go-playground-rm
But of course more reliable solution need.
@grafov The deleted directory locates in a project of my $GOPATH
not in the playground/snippet
folder, far from it.
Oh well it is a bug. I just remove directory where snippet was placed, it assumed the path for snippets is common.
So sorry for your data I will prepare the fix asap.
@grafov I guess that's it, when the frame of my deleted file is gone I started to worry about it, after git status
I realized it's true, I'm doomed...
The first thing that came to me is protect snippet from removing if it placed not under the default path. The second thing is ask for confirmation if non snippet files found in the snippet dir. I hope it will prevent such bad cases with lose of data non related to snippets.
Finally the hotfix (review please):
(defun go-playground-rm ()
"Remove files of the current snippet together with directory of this snippet."
(interactive)
(save-buffer)
(if (string-match-p (file-truename go-playground-basedir) (file-truename (buffer-file-name)))
(progn (delete-directory (file-name-directory (buffer-file-name)) t t)
(kill-buffer))
(message "Won't delete the snippet! Because %s is not under the path %s. Remove it manually!"
(buffer-file-name) go-playground-basedir)))
So it will remove directory only under the snippets path. It should block cause of the problem. I will make the release now. And I will add confirmation variables as described in the message above in next release after this one. So I not close issue yet.