reddit / emacs

Merging directories in dired: am I doing it wrong, or does the functionality I want not exist?

skyler544 · 2022-10-30 09:25
I've tested this with `emacs -Q`, Emacs version 28.2 I'm 99% sure that I'm doing something wrong here, but I can't figure this out: This is the scenario: I have one frame with two windows showing two separate dired buffers, let's call them A and B. A is visiting `~/testA/` and B is visiting `~/testB/`. In both directories, there is a subdirectory `foo/` that I want to merge from buffer A into buffer B, and it doesn't matter if the files within that subdirectory are overwritten (this is what I want to do). I mark `foo/` in buffer A by pressing `m` (`dired-mark`) and press `C` (`dired-do-copy`). I am prompted for the location that I want to copy to; I enter the directory that buffer B is visiting and press RET. Now, I am prompted for whether I would like to overwrite the destination directory, which is what I want. I press `y` or `!`, and then I am asked if I want to copy recursively. I type `yes` and press `RET`. Now the operation fails with an error like this: `Copy: [source-directory] to [destination-directory] failed: (file-already-exists File exists [source-directory] [destination-directory])`. This happens with `dired-do-rename` as well, but without the prompt about recursive copying and a slightly different error: `Move: [source-directory] to [destination-directory] failed: (file-error Renaming Directory not empty [source-directory] [destination-directory])` EDIT: Some more details about the exact steps I can take to reproduce this: 1. open a terminal emulator 2. type `emacs -Q` and press enter 3. press `C-x C-j` (`dired-jump`) 4. press `+` (`dired-create-directory`) 5. type `testA` and press `RET` 6. repeat steps 4 and 5 but create a directory called `testB` 7. enter the `testA` directory by putting point on it and pressing `RET` 8. press `+` and type in `foo` and press `RET` 9. press `C-x C-f` (`find-file`) and type `foo/bar` and press `RET` 10. type something into the new buffer and press `C-x C-s` (`save-buffer`) 11. Copy the folder `~/testA/foo` into `~/testB` somehow, with the shell or with dired 12. change the text in `~/testB/foo/bar` to something else and save it 13. Try to copy the folder `~/testA/foo` into `~/testB` again as outlined above 14. Agree to overwrite with `y` 15. Observe that the command fails
tonicinhibition · 2022-10-30 10:51
I know you're probably looking for a recursive case, but I did just try this and it works for individual files. What I tried then was to enter ~/testA/foo, and then just select all, mark and copy. That worked as well. All documentation for dired's copy functions suggest it's doing something similar to `cp`, `cp -d` or `cp -p` depending on variables in your environment. You're looking for `cp -r`, which likely corresponds to the undocumented function `dired-copy-file-recursive`. Old mail archives fom Stallman seem to suggest the implementation is just calling these programs as described. You could write some elisp using [this question](https://emacs.stackexchange.com/questions/51727/copy-all-dirs-exclude-all-subdirs-with-name-build) as a starting point. Or... I recommend just dropping into shell for anything beyond basic navigation. `eshell` is pretty good and worth learning. It's basically bash+Lisp.
eli-zaretskii · 2022-10-30 11:27
> I enter the directory that buffer B is visiting How did you enter it, exactly? If the directory's name is `~/testA/foo`, what did you type when Emacs prompted for the destination?
skyler544 · 2022-10-30 11:42
With `emacs -Q` the default directory it gives you is `~/testA/`, so I press the backspace key twice and then type `B/` so that the path is `~/testB/` EDIT: That is, the default directory that appears in the minibuffer prompt when you press `C` in the dired buffer visiting `~/testA/` with the directory `foo` marked, is in this case simply `~/testA/`
skyler544 · 2022-10-30 11:45
Is there a function for selecting all subdirectories in a recursive way or something? Either there's something specific to my environment, or you're doing it differently than I am. I was able to reproduce this on another computer as well.
eli-zaretskii · 2022-10-30 14:41
Then please submit a bug reports with these details.
helm05 · 2022-10-31 09:13
The bug comes from copy-directory, I submitted a bug report.