Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1. ignoring @eaDir directories 2. setting UID and GID of copy / move process #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ ENV CRON ""
ENV OPTIONS ""

COPY . /opt/phockup
RUN chmod +x /opt/phockup/entrypoint.sh

RUN apk --no-cache add exiftool \
&& pip install --no-cache-dir -r /opt/phockup/requirements.txt \
&& ln -s /opt/phockup/phockup.py /usr/local/bin/phockup \
&& apk add bash \
&& apk add flock
&& apk add flock \
&& apk add util-linux-login

RUN ["chmod", "-R", "a+rx", "/opt/phockup/"]

ENTRYPOINT ["/opt/phockup/entrypoint.sh"]
41 changes: 30 additions & 11 deletions entrypoint.sh
nigelpatsmith marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
#!/usr/bin/env bash

# If the CRON variable is empty, phockup gets executed once as command line tool
if [ -z "$CRON" ]; then
phockup "$@"
if [[ "$PHOCKUP_UID" != "" && "$PHOCKUP_GID" != "" ]]
nigelpatsmith marked this conversation as resolved.
Show resolved Hide resolved
then
adduser -D -u $PHOCKUP_UID $PHOCKUP_UID || echo "User $PHOCKUP_UID already exists"
addgroup -g $PHOCKUP_GID $PHOCKUP_GID || echo "Group $PHOCKUP_GID already exists"
GNAME=`getent group $PHOCKUP_GID | cut -d: -f1`
if [ -z "$CRON" ]; then
su $PHOCKUP_UID -g $GNAME -c "phockup $*"
else
if [ -f /tmp/phockup.lockfile ]; then
rm /tmp/phockup.lockfile
fi

# When CRON is not empty, phockup will run in a cron job until the container is stopped.
CRON_COMMAND="$CRON flock -n /tmp/phockup.lockfile su $PHOCKUP_UID -g $GNAME -c \"phockup /mnt/input /mnt/output $OPTIONS\""

echo "$CRON_COMMAND" >> /etc/crontabs/root
echo "cron job has been set up with command: $CRON_COMMAND"

crond -f -d 8
fi
else
if [ -f /tmp/phockup.lockfile ]; then
rm /tmp/phockup.lockfile
fi
if [ -z "$CRON" ]; then
phockup "$@"
else
if [ -f /tmp/phockup.lockfile ]; then
rm /tmp/phockup.lockfile
fi

CRON_COMMAND="$CRON flock -n /tmp/phockup.lockfile phockup /mnt/input /mnt/output $OPTIONS"
CRON_COMMAND="$CRON flock -n /tmp/phockup.lockfile phockup /mnt/input /mnt/output $OPTIONS"

echo "$CRON_COMMAND" >> /etc/crontabs/root
echo "cron job has been set up with command: $CRON_COMMAND"
echo "$CRON_COMMAND" >> /etc/crontabs/root
echo "cron job has been set up with command: $CRON_COMMAND"

crond -f -d 8
crond -f -d 8
fi
fi

44 changes: 26 additions & 18 deletions src/phockup.py
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a test that checks if @eaDir is actually ignored. Add the directory in tests/input

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

logger = logging.getLogger('phockup')
ignored_files = ('.DS_Store', 'Thumbs.db')

ignored_dirs = {'@eaDir'}

class Phockup:
DEFAULT_DIR_FORMAT = ['%Y', '%m', '%d']
Expand Down Expand Up @@ -128,24 +128,32 @@ def walk_directory(self):

# Walk the directory
for root, dirnames, files in os.walk(self.input_dir):
files.sort()
file_paths_to_process = []
for filename in files:
if filename in ignored_files:
continue
file_paths_to_process.append(os.path.join(root, filename))
if self.max_concurrency > 1:
if not self.process_files(file_paths_to_process):
return
logger.info(f"walking directory. current dir: {root}, dirnames: {dirnames}, files: {files}")
nigelpatsmith marked this conversation as resolved.
Show resolved Hide resolved
root_set = set(root.split(os.sep))
intersect_set = ignored_dirs.intersection(root_set)
logger.info(f"root_set: {root_set}, ignored_set: {ignored_dirs}, intersection: {intersect_set}")
nigelpatsmith marked this conversation as resolved.
Show resolved Hide resolved
if len(intersect_set) == 0:
files.sort()
file_paths_to_process = []
for filename in files:
if filename in ignored_files:
continue
file_paths_to_process.append(os.path.join(root, filename))
if self.max_concurrency > 1:
if not self.process_files(file_paths_to_process):
return
else:
try:
for file_path in file_paths_to_process:
self.process_file(file_path)
except KeyboardInterrupt:
logger.warning("Received interrupt. Shutting down...")
return
if root.count(os.sep) >= self.stop_depth:
del dirnames[:]
else:
try:
for file_path in file_paths_to_process:
self.process_file(file_path)
except KeyboardInterrupt:
logger.warning("Received interrupt. Shutting down...")
return
if root.count(os.sep) >= self.stop_depth:
del dirnames[:]
logger.info(f"Found directory in ignore list: {root}")
continue

def get_file_count(self):
file_count = 0
Expand Down