Closed ericgaspar closed 4 years ago
I think we should take care of that: https://gitlab.com/mojo42/Jirafeau#from-341-to-400
Thanks for your work @ericgaspar
Good catch
What a wonderful well explain line...
find files -type f ! -name "*_count" | while read f; do bn="$(basename "$f")"; dst="files/${bn:0:8}/${bn:8:8}/${bn:16:8}/${bn:24:8}/"; mkdir -p "$dst"; mv "$f" "$dst" ; mv "${f}_count" "$dst"; done; find files -maxdepth 1 -type d -iname "?" -exec rm -rf {} \;
Considering a file uploaded with the current 3.4.1 looks like that:
/home/yunohost.app/jirafeau/files/a/c/4/0/b/a/a/6/8/1/3/6/e/0/a/9/e/3/1/c/4/4/c/2/6/e/6/6/a/e/8/9/ac40baa68136e0a9e31c44c26e66ae89
And another one with the 4.1.1 like that:
/home/yunohost.app/jirafeau/files/ed2927b6/1c3cf480/c0d9d8fc/2ba50ebf/ed2927b61c3cf480c0d9d8fc2ba50ebf
Such useless madness !!!
I'm in favor of purging all the files and start over.
After a better a look, I see the template, a split every 8 characters. And before a split for each characters.
Anyway, to try to migrate it is a loss of time, and the non commented fucking too long bash line is a no go way...
By the way, the upload password work, whether from an upgrade or from a clean install
I said it would be a loss of time, and still I did it...
main_dir="/home/yunohost.app/jirafeau"
# Migrate files and links to the new directory structure
for type in files links
do
while read file
do
# Ignore _count files
if echo "$file" | grep --quiet "_count$"; then
continue
fi
# Remove all directories before the file name
full_file="$file"
file=$(basename $file)
# Split the file name every 8 characters
split=0
full_path="$main_dir/$type"
while [ $split -le ${#file} ]
do
part_dir="${file:$split:8}"
# Increment the point where with start reading of 8.
split=$((split+8))
full_path="$full_path/$part_dir"
done
# Create the new crazy directory structure
mkdir -p "$full_path"
# And move the file to this place
mv "$full_file" "$full_path/$file"
if [ "$type" = "files" ]; then
mv "${full_file}_count" "$full_path"
fi
done <<< "$(sudo find "$main_dir/$type" -type f)" # List all files, without directories
done
# And clean the old directories
for type in files links
do
while read file
do
# Remove all directories before the last one
dirname="$(basename $file)"
# Delete the directory if it's only one character long
if [ ${#dirname} -eq 1 ]
then
rm -r "$file"
fi
done <<< "$(sudo find "$main_dir/$type" -maxdepth 1 -mindepth 1 -type d)" # List all first level directories
done
Sure it's longer, but it's clear...
@ericgaspar please merge that PR, https://github.com/ericgaspar/jirafeau_ynh/pull/1, so we can reopen the current one and go forward.
Can be merged in 3 days
Problem
Solution
PR Status
Validation
Minor decision
When the PR is marked as ready to merge, you have to wait for 3 days before really merging it.