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

Make it possible to delete a nonempty folders #835

Closed
dhuebner opened this issue Sep 2, 2016 · 32 comments
Closed

Make it possible to delete a nonempty folders #835

dhuebner opened this issue Sep 2, 2016 · 32 comments
Labels
enhancement pkg:filebrowser status:Needs Info status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. tag:Server Change
Milestone

Comments

@dhuebner
Copy link
Member

dhuebner commented Sep 2, 2016

Currently deleting folders which contains other files fails with a dialog:

Delete file
File Delete file

IMHO it should be possible to delete a nonempty folder after warning the user about.

@ellisonbg
Copy link
Contributor

Yeah, I think you are probably right - I find this really annoying. However, we may want to think carefully about this and add an undo action, but that would require cooperation from the server.

@jasongrout
Copy link
Contributor

This works fine for me now on master, at least, on macOS.

@dharmaquark
Copy link
Contributor

it looks like this may still be blocked when running JupyterLab on Windows

@jasongrout
Copy link
Contributor

Can someone test to see if this is still a problem in Windows on master?

@jasongrout jasongrout modified the milestones: Future, 1.0 Feb 14, 2019
@jasongrout
Copy link
Contributor

(CC @vidartf or @ivanov, who may be the only jlab devs running windows?)

@ivanov
Copy link
Member

ivanov commented Feb 15, 2019

JupyterLab 0.35.4 still has this issue.
delete-nonempty

@jasongrout
Copy link
Contributor

What version of the notebook server are you using? This error may come from the notebook server. I know there was some work sometime on windows and sending files to trash.

@albertmichaelj
Copy link

I'm also seeing this issue on Windows.
screen shot 2019-02-26 at 2 57 48 pm

jupyter --version returns 4.4.0, not sure if that is what you mean by notebook server.

@ivanov
Copy link
Member

ivanov commented Feb 26, 2019

What version of the notebook server are you using? This error may come from the notebook server. I know there was some work sometime on windows and sending files to trash.

This was on

jupyter notebook --version
5.6.0

I just tried updating, and get the same error with

jupyter notebook --version
5.7.4

@afshin afshin modified the milestones: 1.0, 1.1 Feb 28, 2019
@jcantrell1
Copy link

Is this still on someone's radar?

@blink1073 blink1073 modified the milestones: 1.1, 1.2 Aug 27, 2019
@albertmichaelj
Copy link

I'm seeing this issue on Jupyter lab 1.0.4 running on Jupyterhub for kubernetes. Not entirely sure if it's a Jupyterhub or Jupyter Lab issue, but this is a very annoying bug for my use case (education).

@lbiemans
Copy link

@albertmichaelj A work-around for us is to just open a terminal and from there do the removal (rm -r foldername).

@albertmichaelj
Copy link

@lbiemans I agree that works well for me personally when I use Jupyter Lab because I am a sophisticated user (and a very heavy user of the command line no matter the OS), but I teach very unsophisticated users using a Jupyterhub deployment. They would be very put off by the idea of using the terminal (particularly because there is no way to open the terminal to the current folder in the sidebar so they have to first navigate to the parent folder and then run rm -r ...).

@lbiemans
Copy link

@albertmichaelj sounds familiar, yeah you are following a programming course but are unable to do some commanline things. Another work-around from inside a notebook is:
%%bash
rm -r foo

Maybe this work-around is usable?

@albertmichaelj
Copy link

@lbiemans Thanks for your suggestions. However, my primary concern with contributing to this github issue is to encourage Jupyter Lab to fix the issue that is preventing deleting non-empty folders in certain conditions. This seems to be a bug because on some platforms (Mac OS, for example), folder delete works perfectly fine even when the folder is non-empty. However, on other platforms (including in the latest jupyter/minimal-notebook docker container with Jupyter-lab 1.1.3 which are official docker containers from the Jupyter project) you can't delete a folder. This inconsistent behavior is a bug, and it is one that is disruptive for non-sophisticated users, which I've always viewed as one of the target audiences for the Jupyter notebook project.

While I understand that there are lots of workarounds that my students could use, they are all much worse than just fixing this bug so that delete behaves consistently on all platforms. I do not think that any command line workarounds (or ipython magic commands) are a good reason not to devote resources to fixing basic usability bugs. I would encourage any maintainer watching this issue to make this a priority. I would also encourage testing against the official jupyter docker container images, since they demonstrate this bug, and it seems to be inconsistent by platform.

@jasongrout
Copy link
Contributor

jasongrout commented Sep 27, 2019

JupyterLab here is most likely just the messenger, conveying the error from the notebook server. My guess is that the notebook server (the notebook package) is the one having the error here, since that is what is actually trying to delete the directory.

To test this hypothesis - can you delete the same directory from the classic notebook? Launch the classic notebook from the JLab Help menu, click the checkbox next to the directory, then the red trash icon at the top to delete it. If you are still getting an error, the problem is in the notebook package and should be filed in the https://github.com/jupyter/notebook/ repo.

@ellisonbg
Copy link
Contributor

ellisonbg commented Sep 27, 2019 via email

@albertmichaelj
Copy link

Yeah, the error does show up on the jupyter notebook as well when I use the jupyter/minimal-notebook docker container. However, this works fine on Mac OS (running directly, not in a container), so the experience is inconsistent across platforms.

If the current design is intentional, one of the problems with it is when you have hidden files. For example, it's common to clone a git repo in various projects. All of the .git directory is hidden, and so you can never delete the repo without resorting to the command line. If this is a deliberate decision, I would encourage at least a config parameter in order to allow for the deletion of non-empty folders.

However, given that it is a server problem, should this issue be moved or referenced there? It's been here forever.

@jasongrout
Copy link
Contributor

Indeed, here is the code in the notebook project that explicitly checks if a directory is empty:

https://github.com/jupyter/notebook/blob/4a9cfa7518c911d1b89b201acd0083adc6fb680e/notebook/services/contents/filemanager.py#L546-L552

That appears to be an intentional design decision, and should be discussed in a https://github.com/jupyter/notebook/ repo issue.

@jasongrout
Copy link
Contributor

However, given that it is a server problem, should this issue be moved or referenced there? It's been here forever.

Please open a new issue there. Sorry, we should have moved it to the server repo from the beginning, where the real issue is.

We do have diagnosis guidelines now at https://jupyterlab.readthedocs.io/en/stable/getting_started/issue.html, and step 3 of those guidelines would have guided someone to post to the notebook server repo.

@albertmichaelj
Copy link

Ok, I just opened an issue with them. One suggestion I made would be to have a confirmation dialogue. Is this something that would have to interact between the frontend and the server? I suspect it would be. Would that be a solution that jupyterlab maintainers would be open to?

@jasongrout
Copy link
Contributor

Is this something that would have to interact between the frontend and the server?

Yes. The way JLab can delete a directory is to call that server function, so there would need to be some way for jlab to instruct the server to delete the directory anyway.

@hemangjoshi37a
Copy link

Has it been already solved??

@Dmitry1987
Copy link

@hemangjoshi37a I had this issue and only solved by patching the filemanager.py (delete send2trash and other Mac/Windows related stuff, if you run notebooks only on linux, and it'll work. the send2trash in my case was not working with either True/False settings), works well now, though i know it's ugly solution.. just couldn't waste any more time for this 😅

@Dmitry1987
Copy link

Just for the sake of people who land here from google search like I did, and who needs a quick and ugly solution for their K8s/docker/linux only setup. The snippet to use in filemanager.py, the delete_file function looks like this in my case [works because just goes straight to deletion when confirmed in the UI. The standard UI dialog box about "do you want to delete this folder" is really more than enough.. no need in any additional confirmations when the folder is non-empty, because in >90% of cases it'll not be empty anyway]:

    def delete_file(self, path):
        """Delete file at path."""
        path = path.strip('/')
        os_path = self._get_os_path(path)
        rm = os.unlink
        if not os.path.exists(os_path):
            raise web.HTTPError(404, u'File or directory does not exist: %s' % os_path)

        if os.path.isdir(os_path):
            self.log.debug("Removing directory %s", os_path)
            with self.perm_to_403():
                shutil.rmtree(os_path)
        else:
            self.log.debug("Unlinking file %s", os_path)
            with self.perm_to_403():
                rm(os_path)

but be careful, it disables the 'send to recycle bin' on wondows/mac

@Dmitry1987
Copy link

oops wrong thread, wanted to post the snippet into this one where the discussion was jupyter/notebook#4916
have gazillion of tabs open about this non-empty folders issues 😅 from both repos, jupyterhub and notebook itself (where the problem really is). oh wow, this repo is jupyterlab? Jesus... this bug is everywhere huh... so I'm basically crossposting the solution across all these threads :D i hope it helps someone.

@telamonian
Copy link
Member

@Dmitry1987 Yep, what you're talking about is code owned by https://github.com/jupyter/notebook

@Jeswin17
Copy link

@albertmichaelj A work-around for us is to just open a terminal and from there do the removal (rm -r foldername).

Yup , thank god for this work-around.

@stefaneidelloth
Copy link

stefaneidelloth commented Oct 23, 2020

Is there some extension solving this issue? For notebooks there is
https://github.com/edina/nb_empty_trash
Also see discussion at jupyter/notebook#4916
As a workaround without code change one can open a terminal in Jupyterlab and enter
rm -r 'Folder name'

@tlvu
Copy link

tlvu commented Dec 4, 2020

+1 for this issue. Not sure why deleting non-empty folders is blocked if user receive a notification that folder is not empty and still want to proceed.

This issue, coupled with #2049 means user will not be able to delete any git checkout since the .git/ folder is hidden and not shown. Even if folder .git/ is shown, drilling down to all folders under .git/ and deleting them one by one is obviously not the way to go.

Being able to dele non-empty folders is a must.

@jasongrout
Copy link
Contributor

As noted above, this is a problem in the server: jupyter/notebook#4916

In JupyterLab 3, we have switched to https://github.com/jupyter-server/jupyter_server (derived from the repo above, so likely has the same bug). https://github.com/jupyter-server/jupyter_server would be where a fix needs to happen for JupyterLab 3 or more.

Closing since this is not a problem with JupyterLab. If you would like to help, please contribute to fixing jupyter/notebook#4916 or filing an issue with https://github.com/jupyter-server/jupyter_server and contribute to fixing that. Thanks!

@GF-Huang
Copy link

GF-Huang commented Mar 5, 2021

image

image

@github-actions github-actions bot added the status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Sep 2, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement pkg:filebrowser status:Needs Info status:resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. tag:Server Change
Projects
None yet
Development

No branches or pull requests