[solved] Mate 1.22.2: cp fails to copy file notes

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
pregrine
Level 2
Level 2
Posts: 50
Joined: Mon Jul 28, 2014 11:48 am

[solved] Mate 1.22.2: cp fails to copy file notes

Post by pregrine »

I want to migrate my files from Mint Mate 19.3 to Mint Mate 21 to a new disk.

Mate has a possibility to add notes to files and directories: right click Properties | Notes on the object – this is the reason, why I use Mate. Unfortunately, no copy program is able to copy these notes. That means, the note will be lost on the migration. That is not acceptable.

I found a script on github, which should be able to copy files including notes: https://gist.github.com/gm10/bc958a381b ... 238c683058, but the script does not copy the notes.

Reason: there is no metadata::annotation.

How to reproduce the issue:
* make a file test
* right click and select Properties | Notes on the file, enter some text and close Properties
* run

Code: Select all

gio info -a metadata::annotation test
gio displays some file attributes, but not the note.

How to copy the file including notes?
Last edited by LockBot on Wed Aug 02, 2023 10:00 pm, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
billyswong
Level 8
Level 8
Posts: 2239
Joined: Wed Aug 14, 2019 1:02 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by billyswong »

I never used this feature.

Take a look at https://crcok.wordpress.com/2011/01/18/ ... for-files/ and see if the script there helps?

(For archival purpose in case the site there is down in the future, here is a copy)

Code: Select all

#!/bin/bash

process_dir() {
 local -a subdirs=()
 echo "Scanning directory: $1"

 # Scan the directory, processing files and collecting subdirs
 for file in "$1"/*; do
 if [[ -f "$file" ]]; then
 echo "Processing file: $file"
 # actually deal with the file here...

 #gvfs-info $file | grep annotation | sed s/' metadata::annotation: '/''/g > $file.note
 note=$(gvfs-info "$file" | grep annotation | sed s/' metadata::annotation: '/''/g)
 #len=`echo ${#note}`
 #echo $len
 if [ -z "$note" ]
 then
 echo "No note for file $file"
 else
 echo "Found a note for file \"$file\", saying: \"$note\""
 echo "$note" > $file.ntext

 fi     # $String is null.

 elif [[ -d "$file" ]]; then
 subdirs+=("$file")
 # If you don't care about processing all files before subfolders, just do:
 # process_dir "$file"
 fi
 done

 # Now go through the subdirs
 for d in "${subdirs[@]}"; do
 process_dir "$d"
 done
}

clear
if [[ -z "$1" ]]; then
 read -p "Please enter a directory for me to scan " dir
else
 dir="$1"
fi
process_dir "$dir"
p.s. According to the aforementioned blog post, this notes feature inherited from Gnome 2 era was stored in ~/.local/share/gvfs-metadata
pregrine
Level 2
Level 2
Posts: 50
Joined: Mon Jul 28, 2014 11:48 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by pregrine »

gvfs-info is the same as gio info, except it is marked as deprecated. It also doesn't find the note.

The script essentially does the job of find to recursively traverse a directory tree.
pregrine
Level 2
Level 2
Posts: 50
Joined: Mon Jul 28, 2014 11:48 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by pregrine »

~/.local/share/gvfs-metadata/root contains file names and the data of all notes – but how to extract data, it's binary file?
pregrine
Level 2
Level 2
Posts: 50
Joined: Mon Jul 28, 2014 11:48 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by pregrine »

Found a trick how to migrate the home folder:

- Copy the hole folder under a new name from the old disk to the new one
- Move the new disk to another machine and change names of the new home folder and the the migrated one
- Move the disk back and reboot the new system

All notes are visible and complete. What says Mint 21 to the config files of Mint 19? I don't know. Maybe I need to merge in the original 21 config files except ~/.local/share/gvfs-metadata.
pregrine
Level 2
Level 2
Posts: 50
Joined: Mon Jul 28, 2014 11:48 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by pregrine »

Whole ~/.local/share/gvfs-metadata/* seems to be a database. It is not possible to extract notes from particular files.

Seems to be a kind of reinvention of Microsoft's top innovation, the Windows Registry, but they forgot to deliver the registry editor…
billyswong
Level 8
Level 8
Posts: 2239
Joined: Wed Aug 14, 2019 1:02 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by billyswong »

Well, there is a real Windows Registry + regedit equivalent in GTK-based desktops. It is called dconf-editor.
pregrine
Level 2
Level 2
Posts: 50
Joined: Mon Jul 28, 2014 11:48 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by pregrine »

Interesting: gio info -a metadata::annotation on Mint 21 works for files, that got their note by caja(Mint 21), but noch for files, that got their note by caja(Mint 19).

What an ill implementation.
pregrine
Level 2
Level 2
Posts: 50
Joined: Mon Jul 28, 2014 11:48 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by pregrine »

billyswong wrote: Fri Feb 03, 2023 10:47 am Well, there is a real Windows Registry + regedit equivalent in GTK-based desktops. It is called dconf-editor.
But dconf-editor doesn't know about file/directory notes, so it won't help……
pregrine
Level 2
Level 2
Posts: 50
Joined: Mon Jul 28, 2014 11:48 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by pregrine »

Where to report this issue with good hope to get a solution within the time, that remains until Mint 19 reaches end of life?
billyswong
Level 8
Level 8
Posts: 2239
Joined: Wed Aug 14, 2019 1:02 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by billyswong »

pregrine wrote: Fri Feb 03, 2023 10:51 am Interesting: gio info -a metadata::annotation on Mint 21 works for files, that got their note by caja(Mint 21), but noch for files, that got their note by caja(Mint 19).

What an ill implementation.
Could you show the whole output of gio info old_file_example? I test the notes feature in LM 19.2 Mate ISO VM, and the notes does show up as metadata::annotation value.
pregrine
Level 2
Level 2
Posts: 50
Joined: Mon Jul 28, 2014 11:48 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by pregrine »

Here is the output og gio info:

Code: Select all

$ gio info -a metadata::annotation hc05.logicsettings
uri: file:///tmp/hc05.logicsettings
local path: /tmp/hc05.logicsettings
unix mount: /dev/mapper/mint-vg-root / ext4 rw,relatime,errors=remount-ro
attributes:
My version is the up to date 19.3 – you are testing with 19.2 and it works? Very interesting.
pregrine
Level 2
Level 2
Posts: 50
Joined: Mon Jul 28, 2014 11:48 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by pregrine »

I can confirm, that gio info -a metadata::annotation hc05.logicsettings works on Mint 19.2 Mate:

Code: Select all

$ gio info -a metadata::annotation hc05.logicsettings
uri: file:///tmp/hc05.logicsettings
attributes:
  metadata::annotation: Logic Analyzer Settings
billyswong
Level 8
Level 8
Posts: 2239
Joined: Wed Aug 14, 2019 1:02 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by billyswong »

pregrine wrote: Fri Feb 03, 2023 12:10 pm Here is the output og gio info:

Code: Select all

$ gio info -a metadata::annotation hc05.logicsettings
uri: file:///tmp/hc05.logicsettings
local path: /tmp/hc05.logicsettings
unix mount: /dev/mapper/mint-vg-root / ext4 rw,relatime,errors=remount-ro
attributes:
My version is the up to date 19.3 – you are testing with 19.2 and it works? Very interesting.
Try exactly gio info hc05.logicsettings in your 19.3 computer. Else we don't know if the note is stored into other attribute names
pregrine
Level 2
Level 2
Posts: 50
Joined: Mon Jul 28, 2014 11:48 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by pregrine »

I found the culprit: I had a version 2.62.? of gio in my PATH, which has been imported via an installation of Anaconda3, which has hidden the original version in /usr/bin. Removing this version solved the problem.

Why the anaconda guys delivered gio, remains their mystery.

Thanks for your support.

Regarding viewtopic.php?p=2291122#p2291122:
The script only handles the very first line of a note. Remaining lines of a multi line note are ignored. Reason is that only the first line contains metadata::annotation. The same is true for the copy script on github. Here is an example:

Code: Select all

$  gio info "optiboot-image-328p-LD4-38400-BT05-release.hex"
display name: optiboot-image-328p-LD4-38400-BT05-release.hex
edit name: optiboot-image-328p-LD4-38400-BT05-release.hex
name: optiboot-image-328p-LD4-38400-BT05-release.hex
type: regular
size:  33596
uri: file:///home/inet/Entwicklung/KiCad/Projekte/Stiefelheizung%20V3/Stiefelheizung%20V2/software/optiboot-image-328p-LD4-38400-BT05-release.hex
attributes:
  standard::type: 1
  standard::name: optiboot-image-328p-LD4-38400-BT05-release.hex
  standard::display-name: optiboot-image-328p-LD4-38400-BT05-release.hex
  standard::edit-name: optiboot-image-328p-LD4-38400-BT05-release.hex
  standard::copy-name: optiboot-image-328p-LD4-38400-BT05-release.hex
  standard::icon: text-x-hex, text-x-generic
  standard::content-type: text/x-hex
  standard::fast-content-type: text/x-hex
  standard::size: 33596
  standard::allocated-size: 36864
  standard::symbolic-icon: text-x-hex-symbolic, text-x-generic-symbolic, text-x-hex, text-x-generic
  etag::value: 1550329386:298518
  id::file: l64769:85592222
  id::filesystem: l64769
  access::can-read: TRUE
  access::can-write: TRUE
  access::can-execute: FALSE
  access::can-delete: TRUE
  access::can-trash: TRUE
  access::can-rename: TRUE
  time::modified: 1550329386
  time::modified-usec: 298518
  time::access: 1675462022
  time::access-usec: 727281
  time::changed: 1567695891
  time::changed-usec: 991434
  unix::device: 64769
  unix::inode: 85592222
  unix::mode: 33188
  unix::nlink: 1
  unix::uid: 1000
  unix::gid: 1000
  unix::rdev: 0
  unix::block-size: 4096
  unix::blocks: 72
  owner::user: inet
  owner::user-real: inet
  owner::group: inet
  metadata::annotation: optiboot für BT05 + BT05-Konfigurator mit

  Taktfrequenz: 10 MHz
  BT05 Baudrate: 38400

  Key-Pin:		C4
  Reset-Pin:	D2
  State-Pin:	C5

  Error-LED:	D4

Flashen:
avrdude -p m328p -P usb -c jtag2isp -U flash:w:optiboot+config-HC05.hex
Fuses setzen:
avrdude -p m328p -P usb -c jtag2isp -U lfuse:w:0xff:m -U hfuse:w:0xde:m -U efuse:w:0x06:m
m328p -P usb -c jtag2isp -U lfuse:w:0xff:m -U hfuse:w:0xde:m -U efuse:w:0x06:m
The note begins at metadata::annotation and ends with avrdude … efuse:w:0x06:m. Several lines of the note are indented.
End criteria is either end of file or a new line beginning with metadata::… – I don't know, if this are all possible cases.

Here is a screenshot of the note: https://www.dropbox.com/s/sbovi2t3a99yl ... 6.png?dl=0

Little joke in passing: try to write a note containing a line " metadata::annotation:"
pregrine
Level 2
Level 2
Posts: 50
Joined: Mon Jul 28, 2014 11:48 am

Re: Mate 1.22.2: cp fails to copy file notes

Post by pregrine »

Here is a script, that extracts file/directory notes from a whole directory tree an prints a script to import these notes to another directory tree.

Code: Select all

#!/bin/bash
# usage: extract-annotations.sh >import-annotaions.sh

root=~

# collect file/directory paths
echo "collecting file names" >&2
filelist=$(mktemp -t 'noteFileListXXXX')
find "$root" >"$filelist" 2>/tmp/note-find-errors

# extract data
echo "collecting meta information" >&2
info=$(mktemp -t 'noteInfoXXXX')
while IFS= read -r f ; do
	echo "$f"  >>"$info"
	gio info "$f" >>"$info"
	#gvfs-info "$f" >>"$info"
	echo $'\f' >>"$info"
done < "$filelist"

rm "$filelist"

# generate output
echo "generating output" >&2
gawk -f <(cat - <<-'_EOF_'
	BEGIN {
		trace = 0
		state = 0
		file = ""
		buf = ""
		numFiles = 0
		# if (trace) print  "<state " state "> "
		print "#!/bin/bash\n"
	}
	
	state == 0 {
		# file name
		file = "\"" $0 "\""
		# if (trace) printf  "<state %d> %s\n", state, file
		buf = ""
		state = 1
		next
	}
	
	state == 1 && /\f/ {
		# if (trace) print  "<state " state "> "
		state = 0
		next
	}
	
	state == 1 && /metadata::annotation/ {
		# first metadata::annotation
		# if (trace) print  "<state " state "> "
		gsub(/^  metadata::[^:]+: /, "")
		if (!match($0, /^\s*$/))
			buf = buf $0 "\n"
		numFiles++
		state++
		next
	}

	state >= 2 && /\f/ {
		# ff – output, if buf contains data
		# if (trace) print  "<state " state "> \"" $0 "\""
		if (!match(buf, /^\s*$/)) {
			gsub("'", "\\'", buf)
			printf "gio set %s metadata::annotation '%s'\n", file, buf
		}
		state = 0
		next
	}
	
	state == 2 && /metadata::/ {
		# metadata::*
		# if (trace) print  "<state " state "> \"" $0 "\""
		state++
		next
	}
	
	state == 2 {
		# anything between metadata::annotation and ff
		# if (trace) print  "<state " state "> \"" $0 "\""
		buf = buf  $0 "\n"
		next
	}
	
	END {
		printf "Number of notes found: %d\n", numFiles >"/dev/stderr"
	}
_EOF_
) "$info"

rm "$info"
Be aware that this script may run for hours on large directory trees. The most time consuming part is the loop around gio info.
Redirect the output to a file and execute it on the target system.
Locked

Return to “Software & Applications”