Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

RSYNC extension #1708

Merged
merged 23 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions doc/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ recipe:

FROM almalinux:8
RUN yum -y install python36
RSYNC ./hello.py /
COPY ./hello.py /
RUN chmod 755 /hello.py

These four instructions say:
Expand All @@ -275,14 +275,18 @@ These four instructions say:
2. :code:`RUN`: Install the :code:`python36` RPM package, which we need for
our Hello World program.

3. :code:`RSYNC`: Copy the file :code:`hello.py` we just made to the root
3. :code:`COPY`: Copy the file :code:`hello.py` we just made to the root
directory of the image. In the source argument, the path is relative to
the *context directory*, which we’ll see more of below. (This instruction
is a Charliecloud extension; see :ref:`its documentation <ch-image_rsync>`
for details.) You can also use standard :code:`COPY` if you prefer.)
the *context directory*, which we’ll see more of below.

4. :code:`RUN`: Make that file executable.

.. note::

:code:`COPY` is a standard instruction but has a number of disadvantages in
its corner cases. Charliecloud also has :code:`RSYNC`, which addresses
these; see :ref:`its documentation <ch-image_rsync>` for details.

Let’s build this image::

$ ch-image build -t hello -f Dockerfile .
Expand Down
27 changes: 26 additions & 1 deletion lib/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,31 @@ def git_incompatible_p(self):
"Return True if I can’t be stored in Git because of my name."
return self.name.startswith(".git")

@property
def is_root(self):
return (str(self) == "/")

@property
def mountpoint(self):
"""Return the mount point of the filesystem containing me (or, if
symlink, the file pointed to)."""
# https://stackoverflow.com/a/4453715
try:
pc = self.resolve(strict=True)
except RuntimeError:
ch.FATAL("not found, can’t resolve: %s" % self)
# Unclear whether ismount() deals correctly with the root directory, so
# do the stat(2) stuff ourself.
dev_child = pc.stat().st_dev
while (not pc.is_root):
dev_parent = pc.parent.stat().st_dev
if (dev_child != dev_parent):
return pc
pc = pc.parent
# Got all the way up to root without finding a transition, so we’re on
# the root filesystem.
return Path("/")

@property
def parent(self):
ret = super().parent
Expand Down Expand Up @@ -340,7 +365,7 @@ def is_relative_to(self, *other):

def joinpath_posix(self, right):
# This method is a hot spot, so the hairiness is due to optimizations.
# It runs about 30% faster than the naïve verson below.
# It runs about 30% faster than the naïve verson referenced below.
reidpr marked this conversation as resolved.
Show resolved Hide resolved
if (isinstance(right, Path)):
right_parts = right._parts
ts_p = right.trailing_slash_p
Expand Down
6 changes: 3 additions & 3 deletions test/build/55_cache.bats
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,10 @@ EOF
# Prepare fixtures. These need various manipulating during the test, which
# is why they’re built here on the fly.
fixtures=${BATS_TMPDIR}/rsync-cache
mkdir -p "$fixtures"
rm -Rf --one-file-system "$fixtures"
mkdir "$fixtures"
echo hello > "$fixtures"/file1
rm -f "$fixtures"/file1a
mkdir -p "$fixtures"/dir1
mkdir "$fixtures"/dir1
touch "$fixtures"/dir1/file1 "$fixtures"/dir1/file2

printf '\n*** Build; all misses.\n\n'
reidpr marked this conversation as resolved.
Show resolved Hide resolved
Expand Down