First, note that this is not a plain 'merge two directories', this is a question about how to keep the merge of said directories updated when the sources change.
Let us say that I have two directories a
and b
and I want to merge them into c
with the following rules:
- Entries from
a
must always be inc
regardless of their existence or last modified timestamp. - Fill the gaps with
b
.
A simple cp
from b
to c
and overwriting with a
where necessary does the job (copies more than necessary, but it is intended to be used only once)
Now, what I want is some way of keeping this updated (as this is intended to be in a Makefile
) So, if there is a new file in a
, make
copies it. If there is a new file in b
, make
copies it only if it is not already in c
. If a file from a
is updated, make
, updates it in c
and if a file from b
is updated, it is updated in c
only if it came from b
but not if it came from a
.
I hope I have explained it accurately.
make
the tool you've chosen for this? – mattdm Dec 17 '19 at 14:44rm
followed by two copies. It works, but it needs to copy everything even if just a tiny thing changed.cp -u
works for the copy froma
but only in the cases where the file fromb
is older than the one ina
so it is not fully reliable.make
has been chosen just as a 'wrapper' as this is intended to be used asmake update
. – Noxbru Dec 17 '19 at 14:52