{"thread":{"id":"2815","subject":"[PATCH] cg-clean: fix directory cleaning","startedAt":"2005-12-12T20:54:20Z","lastAt":"2005-12-13T00:42:51Z","messageCount":2,"participants":["Pavel Roskin","Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"13528","messageId":"1134420860.4695.14.camel@dv","threadId":"2815","inReplyTo":null,"subject":"[PATCH] cg-clean: fix directory cleaning","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2005-12-12T20:54:20Z","receivedAt":"2005-12-12T20:54:20Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"cg-clean is broken by commit 3cddede46dcd24bd7c36827ca564de23b2bb3517 -\nit removes all subdirectories when run in the top level directory.\n\nAlthough it's easy to make a one-line fix, I'd prefer a solution that\nmakes cg-clean potentially safer.  Since git-ls-files runs in\nsubdirectories now, it's no longer needed to run anything in the top\nlevel directory and filter out the results.  cg-clean now changes to\n$_git_relpath on startup and never uses $_git_relpath again.\n\nSigned-off-by: Pavel Roskin <proski@gnu.org>\n\ndiff --git a/cg-clean b/cg-clean\nindex 92fc48e..6909076 100755\n--- a/cg-clean\n+++ b/cg-clean\n@@ -60,8 +60,6 @@ clean_dirs()\n \tgit-ls-files --cached |\n \t\tsed -n 's|/[^/]*$||p' |\n \t\twhile IFS=$'\\n' read dir; do\n-\t\t\t[ x\"${dir#$_git_relpath}\" = x\"${dir}\" ] && continue\n-\t\t\tdir=\"${dir#$_git_relpath}\"\n \t\t\twhile true; do\n \t\t\t\techo \"$dir\"\n \t\t\t\tupdir=\"${dir%/*}\"\n@@ -74,32 +72,27 @@ clean_dirs()\n \tsave_IFS=\"$IFS\"\n \tIFS=$'\\n'\n \n-\tfpath=${_git_relpath-./}\n-\tfind \"$fpath\" -type d -print |\n-\t\twhile read dir; do\n-\t\t\techo \"${dir#$fpath}\"\n-\t\tdone |\n-\t\tsed '/^$/d;/^\\.git$/d;/^\\.git\\//d' |\n+\tfind ./ -type d -print |\n+\t\tsed 's/^\\.\\///;/^$/d;/^\\.git$/d;/^\\.git\\//d' |\n \t\tcat - \"$dirlist\" | sort -u |\n \t\tdiff - \"$dirlist\" |\n \t\tsed -n 's/< //p' |\n-\twhile read file; do\n-\t\tpath=\"${_git_relpath}$file\"\n-\t\tif [ ! -d \"$path\" ]; then\n+\twhile read dir; do\n+\t\tif [ ! -d \"$dir\" ]; then\n \t\t\t# Perhaps directory was removed with its parent\n \t\t\tcontinue\n \t\tfi\n \t\tif [ -z \"$cleandir\" ]; then\n-\t\t\techo \"Not removing $file/\"\n+\t\t\techo \"Not removing $dir/\"\n \t\t\tcontinue\n \t\tfi\n-\t\t[ \"$quiet\" ] || echo \"Removing $file/\"\n+\t\t[ \"$quiet\" ] || echo \"Removing $dir/\"\n \t\tif [ \"$cleandirhard\" ]; then\n-\t\t\tchmod -R 700 \"$path\"\n+\t\t\tchmod -R 700 \"$dir\"\n \t\tfi\n-\t\t$rm -rf \"$path\"\n-\t\tif [ -e \"$path\" -o -L \"$path\" ]; then\n-\t\t\techo \"Cannot remove $file/\"\n+\t\t$rm -rf \"$dir\"\n+\t\tif [ -e \"$dir\" -o -L \"$dir\" ]; then\n+\t\t\techo \"Cannot remove $dir/\"\n \t\tfi\n \tdone\n \n@@ -117,14 +110,13 @@ clean_files()\n \n \tcg-status -n -s '?' \"$xopt\" -w |\n \twhile read file; do\n-\t\tpath=\"${_git_relpath}$file\"\n-\t\tif [ -d \"$path\" -a ! -L \"$path\" ]; then\n+\t\tif [ -d \"$file\" -a ! -L \"$file\" ]; then\n \t\t\t# Sanity check, shouldn't happen\n \t\t\techo \"FATAL: cg-status reports directories (internal error)\" >&2\n \t\t\texit 1\n-\t\telif [ -e \"$path\" -o -L \"$path\" ]; then\n+\t\telif [ -e \"$file\" -o -L \"$file\" ]; then\n \t\t\t[ \"$quiet\" ] || echo \"Removing $file\"\n-\t\t\t$rm -f \"$path\"\n+\t\t\t$rm -f \"$file\"\n \t\t\t# rm would complain itself on failure\n \t\telse\n \t\t\techo \"File $file has disappeared!\"\n@@ -135,6 +127,8 @@ clean_files()\n }\n \n \n+cd \"${_git_relpath-.}\"\n+\n # Even if -d or -D is not specified, we want to tell user about\n # directories that are not removed\n if [ -z \"$quiet\" -o \"$cleandir\" ]; then\n\n\n-- \nRegards,\nPavel Roskin\n"},{"id":"13540","messageId":"20051213004251.GA22159@pasky.or.cz","threadId":"2815","inReplyTo":"1134420860.4695.14.camel@dv","subject":"Re: [PATCH] cg-clean: fix directory cleaning","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2005-12-13T00:42:51Z","receivedAt":"2005-12-13T00:42:51Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Mon, Dec 12, 2005 at 09:54:20PM CET, I got a letter\nwhere Pavel Roskin <proski@gnu.org> said that...\n> cg-clean is broken by commit 3cddede46dcd24bd7c36827ca564de23b2bb3517 -\n> it removes all subdirectories when run in the top level directory.\n> \n> Although it's easy to make a one-line fix, I'd prefer a solution that\n> makes cg-clean potentially safer.  Since git-ls-files runs in\n> subdirectories now, it's no longer needed to run anything in the top\n> level directory and filter out the results.  cg-clean now changes to\n> $_git_relpath on startup and never uses $_git_relpath again.\n> \n> Signed-off-by: Pavel Roskin <proski@gnu.org>\n\nOops! Many thanks to both this and the testcase - I was just about to\nwrite one, because those cg-clean bugs are really quite ugly. I'll\nrelease 0.16.2 tomorrow if no other bug will be found.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nVI has two modes: the one in which it beeps and the one in which\nit doesn't.\n"}]}