Bug 3845 - Make --remove-source-files remove directories too
Summary: Make --remove-source-files remove directories too
Status: ASSIGNED
Alias: None
Product: rsync
Classification: Unclassified
Component: core (show other bugs)
Version: 2.6.9
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---
Assignee: Wayne Davison
QA Contact: Rsync QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-16 15:43 UTC by Matt McCutchen
Modified: 2020-05-26 16:25 UTC (History)
9 users (show)

See Also:


Attachments
Add --remove-source-files option (13.33 KB, patch)
2006-06-30 11:03 UTC, Wayne Davison
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matt McCutchen 2006-06-16 15:43:21 UTC
Let's have a --remove-source-files option that works like --remove-sent-files but removes from the source everything in the file list, not just transferred files.  Then I could use rsync for my primary move command (via a wrapper called "mv2") as well as my primary copy command ("cp2").
Comment 1 Wayne Davison 2006-06-19 14:40:26 UTC
Yes, I think this is a good idea, particularly because of the problem rsync has doing the right thing when restarting an interrupted transfer that is using --remove-sent-files (i.e. some of the sent files might not get removed).

Because of this, I'm thinking about deprecating --remove-sent-files (but leaving it supported to work with older versions).
Comment 2 J.C. Wren 2006-06-27 22:59:25 UTC
Is there a possible ETA for this feature?  It would nicely solve the problem I have with files getting left over after a GPRS link goes down in mid-transfer.  My current, and rather gross, solution is to summarily delete everything in the transfer directory after rsync completes successfully.  

--jc

(In reply to comment #0)
> Let's have a --remove-source-files option that works like --remove-sent-files
> but removes from the source everything in the file list, not just transferred
> files.  Then I could use rsync for my primary move command (via a wrapper
> called "mv2") as well as my primary copy command ("cp2").
> 

Comment 3 Wayne Davison 2006-06-30 11:03:08 UTC
Created attachment 2010 [details]
Add --remove-source-files option

Here is a patch that adds the --remove-source-files option and deprecates the --remove-sent-files option.  I've also checked this into CVS, so it is also available from there or the latest nightly tar file.

The code is young, but should be safe as most of the functionality was taken from remove-sent-files.  I've run basic tests on it, and it works fine.
Comment 4 Matt McCutchen 2007-02-21 19:13:33 UTC
A --remove-source-files option was added in 2.6.9, but it does not remove source directories, and I would like it to remove them so that "rsync --remove-source-files" can be used as a mv replacement.  Specifically, I would like the sender to do the following:

(1) Remove each empty source directory as soon as the generator processes it.  (For this to work, the generator would need to send MSG_SUCCESS after processing a directory with no contents in the file list; maybe the --prune-empty-dirs code could be reused to flag such directories.)

(2) After removing each source file, check whether the parent directory is empty and in the file list.  If so, remove it and recursively consider /its/ parent for removal.

I would be satisfied if a separate option or repetition of --remove-source-files activated this behavior.
Comment 5 Joachim Kluge 2008-03-10 04:45:40 UTC
What's the status of this feature? The directory deletion feature is still missing. I'm on 2.6.9 but I couldn't find changes in the Changelog of 3.0.
Comment 6 Leho Kraav 2009-10-18 16:05:29 UTC
registered a new account here for this one. really nobody has cared enough to implement it yet?

# rsync --version
rsync  version 3.0.5  protocol version 30
Comment 7 Tammer Ibrahim 2012-05-07 12:56:59 UTC
Hello,

I'm also quite interested in this feature. Rsync is already the perfect augmentation of the cp command, and adding this feature would similarly allow an easy drop-in augmentation of the mv command.
Comment 8 Rian 2012-07-06 01:05:59 UTC
I too am interested in this feature as I pull from a remote server that I have no shell access too.
I don't have access to run rm -rf or such after the pull is complete so I just have hundred of empty directories sitting on that server.