Skip to content

Instantly share code, notes, and snippets.

@gm10
Created June 25, 2019 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gm10/bc958a381b83d9c62baf58238c683058 to your computer and use it in GitHub Desktop.
Save gm10/bc958a381b83d9c62baf58238c683058 to your computer and use it in GitHub Desktop.
Copy directories while preserving metadata::annotation (Caja Notes)
#!/bin/bash
#
# Copy directories while preserving metadata::annotation
# (C) 2019 gm10
#
if [[ -z $1 || -z $2 ]]; then
echo "Usage: $(basename $0) <source-directory> <target-directory>"
exit
fi
if [[ ! -d $1 ]]; then
echo "Source must be a directory"
exit
fi
if [[ -e $2 ]]; then
if [[ ! -d $2 ]]; then
echo "Destination must be a directory"
exit
fi
else
mkdir -p "$2"
fi
_SOURCE=$1
_DEST=$2
export _SOURCE
export _DEST
cp -a "$1"/* "$2"
find "$1" -exec bash -c '
for f do
annotation=$(gio info -a metadata::annotation "$f"|grep metadata::annotation|awk -F '\''metadata::annotation: '\'' '\''{print $2;}'\'')
[[ ! -z $annotation ]] && gio set "${_DEST}/${f#"$_SOURCE"}" metadata::annotation "$annotation"
done
' {} +
@ajfre
Copy link

ajfre commented Feb 3, 2023

This script doesn't find any metadata::annotation on Linux Mint 19.3

The reason seems to be a problem with gio 2.69.1 on Mint 19.3.

gio 2.56.4 on Mint 19.2 works.

@ajfre
Copy link

ajfre commented Feb 6, 2023

Correction: the original version of 19.3, gio 2.56.4, works.

copy-dir-with-annotation.sh truncates multi line notes to one-liners.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment