Skip to content

Commit

Permalink
Implement .rsync-ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhinch committed Aug 27, 2019
1 parent f38a350 commit 1673999
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,12 @@ Synchronisation is performed by comparing the date and time of source
and destination files. Files are copied if the source is newer than the
destination.

Synchronisation can be configured to ignore files such as documents,
usually to conserve space on the destination. This is done by means
of a file named .rsync-ignore. This should comprise a list of files
and/or subdirectories with each item on a separate line. If such a
file is found in a source directory, items found in the file's
directory that match its contents will not be synchronised.

shell
-----
Expand Down
22 changes: 21 additions & 1 deletion rshell/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@
RTS = ''
DTR = ''

IGFILE_NAME = '.rshell-ignore'

# It turns out that just because pyudev is installed doesn't mean that
# it can actually be used. So we only bother to try if we're running
# under linux.
Expand Down Expand Up @@ -875,6 +877,21 @@ def rsync(src_dir, dst_dir, mirror, dry_run, print_func, recursed, sync_hidden):
for name, stat in src_files:
d_src[name] = stat

# Check source for an ignore file
all_src = auto(listdir_stat, src_dir, show_hidden=True)
igfiles = [x for x in all_src if x[0] == IGFILE_NAME]
set_ignore = set()
if len(igfiles):
igfile, mode = igfiles[0]
if mode_isfile(stat_mode(mode)):
with open(src_dir + '/' + igfile, 'r') as f:
for line in f.readlines():
line = line.strip()
if line:
set_ignore.add(line)
else:
print_err('Ignore file "{:s}" is not a file'.format(IGFILE_NAME))

d_dst = {}
dst_files = auto(listdir_stat, dst_dir, show_hidden=sync_hidden)
if dst_files is None: # Directory does not exist
Expand All @@ -885,7 +902,7 @@ def rsync(src_dir, dst_dir, mirror, dry_run, print_func, recursed, sync_hidden):
d_dst[name] = stat

set_dst = set(d_dst.keys())
set_src = set(d_src.keys())
set_src = set(d_src.keys()) - set_ignore
to_add = set_src - set_dst # Files to copy to dest
to_del = set_dst - set_src # To delete from dest
to_upd = set_dst.intersection(set_src) # In both: may need updating
Expand Down Expand Up @@ -2647,6 +2664,9 @@ def do_shell(self, line):
),
)

def complete_rsync(self, text, line, begidx, endidx):
return self.filename_complete(text, line, begidx, endidx)

def do_rsync(self, line):
"""rsync [-m|--mirror] [-n|--dry-run] [-q|--quiet] SRC_DIR DEST_DIR
Expand Down

0 comments on commit 1673999

Please sign in to comment.