Skip to content

Commit dfbff61

Browse files
committed
shredder: optimise bootstrapping
- use compile-time length - remove trailing spaces - fix comment
1 parent 7c78835 commit dfbff61

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

lib/cmdline.c

+24-24
Original file line numberDiff line numberDiff line change
@@ -135,30 +135,30 @@ static void rm_cmd_show_manpage(void) {
135135
* We try to work around this by manually installing dist-packages to the
136136
* sys.path by first calling a small bootstrap script.
137137
*/
138-
static const char RM_PY_BOOTSTRAP[] =
138+
static const char rm_py_bootstrap[] =
139139
""
140-
"# This is a bootstrap script for the rmlint-gui. \n"
141-
"# See the src/rmlint.c in rmlint's source for more info. \n"
142-
"import sys, os, site \n"
143-
" \n"
144-
"# Also default to dist-packages on debian(-based): \n"
145-
"sites = site.getsitepackages() \n"
146-
"sys.path.extend([d.replace('dist-packages', 'site-packages') for d in sites]) \n"
147-
"sys.path.extend(sites) \n"
148-
" \n"
149-
"# Cleanup self: \n"
150-
"try: \n"
151-
" os.remove(sys.argv[0]) \n"
152-
"except: \n"
153-
" print('Note: Could not remove bootstrap script at ', sys.argv[0]) \n"
154-
" \n"
155-
"# Run shredder by importing the main: \n"
156-
"try: \n"
157-
" import shredder \n"
158-
" shredder.run_gui() \n"
159-
"except ImportError as err: \n"
160-
" print('Failed to load shredder:', err) \n"
161-
" print('This might be due to a corrupted install; try reinstalling.') \n";
140+
"# This is a bootstrap script for rmlint-gui (aka Shredder)\n"
141+
"# See the lib/cmdline.c in rmlint's source for more info.\n"
142+
"import sys, os, site\n"
143+
"\n"
144+
"# Also default to dist-packages on debian(-based):\n"
145+
"sites = site.getsitepackages()\n"
146+
"sys.path.extend([d.replace('dist-packages', 'site-packages') for d in sites])\n"
147+
"sys.path.extend(sites)\n"
148+
"\n"
149+
"# Cleanup self:\n"
150+
"try:\n"
151+
" os.remove(sys.argv[0])\n"
152+
"except:\n"
153+
" print('Note: Could not remove bootstrap script at ', sys.argv[0])\n"
154+
"\n"
155+
"# Run shredder:\n"
156+
"try:\n"
157+
" import shredder\n"
158+
" shredder.run_gui()\n"
159+
"except ImportError as err:\n"
160+
" print('Failed to load shredder:', err)\n"
161+
" print('This might be due to a corrupted install; try reinstalling.')\n";
162162

163163
static void rm_cmd_start_gui(int argc, const char **argv) {
164164
const char *commands[] = {"python3", "python", NULL};
@@ -176,7 +176,7 @@ static void rm_cmd_start_gui(int argc, const char **argv) {
176176
return;
177177
}
178178

179-
if(write(bootstrap_fd, RM_PY_BOOTSTRAP, strlen(RM_PY_BOOTSTRAP)) < 0) {
179+
if(write(bootstrap_fd, rm_py_bootstrap, sizeof(rm_py_bootstrap) - 1) < 0) {
180180
rm_log_warning_line("Could not bootstrap gui: Unable to write to tempfile: %s",
181181
g_strerror(errno));
182182
return;

0 commit comments

Comments
 (0)