summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlashbunny2021-04-08 19:15:10 -0400
committerSlashbunny2021-04-08 19:15:10 -0400
commit9a1cc869d5e0df926cef9a98b15563a5ce593872 (patch)
treeeb25a0a43d9fbd1e1802a53b9920159c6d8f202f
parentd2e8a9bc44f1cdd1b294a46213d9479fae3f96bf (diff)
downloadaur-defrag.tar.gz
Patch to fix issue with call to /proc/meminfo
Also apply additional corrections based on shellcheck
-rw-r--r--.SRCINFO4
-rw-r--r--PKGBUILD13
-rw-r--r--shellcheck-fixes.patch126
3 files changed, 139 insertions, 4 deletions
diff --git a/.SRCINFO b/.SRCINFO
index a842101eef71..cae950d06e72 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,12 +1,14 @@
pkgbase = defrag
pkgdesc = A braindead simple and filesystem agnostic defragmentation script
pkgver = 0.08
- pkgrel = 1
+ pkgrel = 2
url = http://ck.kolivas.org/apps/defrag/
arch = any
depends = bash
source = http://ck.kolivas.org/apps/defrag/defrag-0.08/defrag
+ source = shellcheck-fixes.patch
sha512sums = fa1c9c3a58ec43020a6a1da66bcbf8304e9b2ad1afbd25c0aab0962410e977412954669be2ae2aaaf8b14b2294cad91bbb0143f589688aa684080dff1b2c5316
+ sha512sums = bd562680b4c049a1e9b1704b2da2f94f7ba8037625f0a6501d75417d90cce09d10fc59ecd2e0c8f49252d7a7868da36ec2e810a660adefa76b6cc1ce6ecc2f42
pkgname = defrag
diff --git a/PKGBUILD b/PKGBUILD
index a8e789b5824e..dc3538369c1b 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -2,14 +2,21 @@
pkgname=defrag
pkgver=0.08
-pkgrel=1
+pkgrel=2
pkgdesc="A braindead simple and filesystem agnostic defragmentation script"
url="http://ck.kolivas.org/apps/defrag/"
license=()
depends=('bash')
arch=('any')
-source=("http://ck.kolivas.org/apps/defrag/$pkgname-$pkgver/defrag")
-sha512sums=('fa1c9c3a58ec43020a6a1da66bcbf8304e9b2ad1afbd25c0aab0962410e977412954669be2ae2aaaf8b14b2294cad91bbb0143f589688aa684080dff1b2c5316')
+source=("http://ck.kolivas.org/apps/defrag/$pkgname-$pkgver/defrag" 'shellcheck-fixes.patch')
+sha512sums=('fa1c9c3a58ec43020a6a1da66bcbf8304e9b2ad1afbd25c0aab0962410e977412954669be2ae2aaaf8b14b2294cad91bbb0143f589688aa684080dff1b2c5316'
+ 'bd562680b4c049a1e9b1704b2da2f94f7ba8037625f0a6501d75417d90cce09d10fc59ecd2e0c8f49252d7a7868da36ec2e810a660adefa76b6cc1ce6ecc2f42')
+
+prepare() {
+ cd "${srcdir}"
+
+ patch --follow-symlinks -p1 -i shellcheck-fixes.patch
+}
package() {
cd "${srcdir}"
diff --git a/shellcheck-fixes.patch b/shellcheck-fixes.patch
new file mode 100644
index 000000000000..299b86f30b4f
--- /dev/null
+++ b/shellcheck-fixes.patch
@@ -0,0 +1,126 @@
+diff --git a/defrag b/defrag
+index 7210343..a7d91f6 100755
+--- a/defrag
++++ b/defrag
+@@ -27,9 +27,9 @@ fail()
+ declare -i filesize=0
+ declare -i numfiles=0
+
+-#The maximum size of a file we can easily cache in ram
+-declare -i maxsize=$((`awk '/MemTotal/ {print $2}' /proc/meminfo`*1024))
+-(( maxsize-= `awk '/Mapped/ {print $2}' /proc/meminfo` ))
++# The maximum size of a file we can easily cache in ram
++declare -i maxsize=$(($(awk '/MemTotal/ {print $2}' /proc/meminfo)*1024))
++(( maxsize-= $(awk '/^Mapped/ {print $2}' /proc/meminfo)))
+ (( maxsize/= 2))
+
+ if [[ -a tmpfile || -a dirlist ]] ; then
+@@ -45,56 +45,56 @@ fi
+
+ echo "Creating list of files..."
+
+-#stupid script to find max directory depth
+-find -xdev -type d -printf "%d\n" | sort -n | uniq > dirlist
++# stupid script to find max directory depth
++find . -xdev -type d -printf "%d\n" | sort -n | uniq >dirlist
+
+-#sort directories in descending size order
+-cat dirlist | while read d;
++# sort directories in descending size order
++while read -r d;
+ do
+- find -xdev -type d -mindepth $d -maxdepth $d -printf "\"%p\"\n" | \
+- xargs du -bS --max-depth=0 | \
+- sort -k 1,1nr -k 2 |\
+- cut -f2 >> tmpfile
+- if (( $? )) ; then
++ if ! find . -xdev -type d -mindepth "$d" -maxdepth "$d" -printf "\"%p\"\n" | \
++ xargs du -bS --max-depth=0 | \
++ sort -k 1,1nr -k 2 | \
++ cut -f 2 >>tmpfile
++ then
+ fail
+ fi
+
+-done
++done <dirlist
+
+ rm -f dirlist
+
+-#sort files in descending size order
+-cat tmpfile | while read d;
++# sort files in descending size order
++while read -r d;
+ do
+- find "$d" -xdev -type f -maxdepth 1 -printf "%s\t%p\n" | \
+- sort -k 1,1nr | \
+- cut -f2 >> dirlist
+- if (( $? )) ; then
++ if ! find "$d" -xdev -type f -maxdepth 1 -printf "%s\t%p\n" | \
++ sort -k 1,1nr | \
++ cut -f 2 >>dirlist
++ then
+ fail
+ fi
+-done
++done <tmpfile
+
+ rm -f tmpfile
+
+-numfiles=`wc -l dirlist | awk '{print $1}'`
++numfiles=$(wc -l dirlist | awk '{print $1}')
+
+ echo -e "$numfiles files will be reordered\n"
+
+-#copy to temp file, check the file hasn't changed and then overwrite original
+-cat dirlist | while read i;
++# copy to temp file, check the file hasn't changed and then overwrite original
++while read -r i;
+ do
+ (( --numfiles ))
+ if [[ ! -f $i ]]; then
+ continue
+ fi
+
+- #We could be this paranoid but it would slow it down 1000 times
++ # We could be this paranoid but it would slow it down 1000 times
+ #if [[ `lsof -f -- "$i"` ]]; then
+ # echo -e "\n File $i open! Skipping"
+ # continue
+ #fi
+
+- filesize=`find "$i" -printf "%s"`
++ filesize=$(find "$i" -printf "%s")
+ # read the file first to cache it in ram if possible
+ if (( filesize < maxsize ))
+ then
+@@ -104,22 +104,20 @@ do
+ echo -e "\r $numfiles files left - Reordering large file sized $filesize ... \c"
+ fi
+
+- datestamp=`find "$i" -printf "%s"`
+- cp -a -f "$i" tmpfile
+- if (( $? )) ; then
++ datestamp=$(find "$i" -printf "%s")
++ if ! cp -a -f "$i" tmpfile; then
+ fail
+ fi
+ # check the file hasn't been altered since we copied it
+- if [[ `find "$i" -printf "%s"` != $datestamp ]] ; then
++ if [[ $(find "$i" -printf "%s") != "$datestamp" ]] ; then
+ continue
+ fi
+
+- mv -f tmpfile "$i"
+- if (( $? )) ; then
++ if ! mv -f tmpfile "$i"; then
+ fail
+ fi
+-done
+-
+-echo -e "\nSucceeded"
++done <dirlist
+
+ rm -f dirlist
++
++echo -e "\nSucceeded"