Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000174incronpublic2010-05-21 00:572010-05-21 17:49
Reportercpm 
Assigned Toluk 
PriorityurgentSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Summary0000174: Spaces in Event-related file names are not escaped when passed on
DescriptionIf I pass $# to a command and the file name has spaces in it, the parameters come through as separate arguments.
I tried wrapping it in quotes like "$#", but I still get the file name come through as separate arguments that I have to piece together again afterwards.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0000139)
neilm (reporter)
2008-04-06 08:50

I can confirm this issue.
(0000283)
tamasrepus (reporter)
2008-10-23 23:47

Confirming as well.

This issue is a severely hinders incron's utility to me... I can't control whether filenames contain spaces or not. It's difficult and unreliable to piece arguments back together to form the original filename (some filenames contain multiple consecutive spaces).
(0000284)
tamasrepus (reporter)
2008-10-24 02:41

Thinking about it a bit more, I found a workaround easily enough... run your program through a shell. E.g., instead of:

/path IN_CLOSE_WRITE /bin/myscript $@/$#

do:

/path IN_CLOSE_WRITE /bin/sh -c '/bin/myscript "$@/@#"'

If nothing to address this will be added in upstream, perhaps it should be added to the FAQ?
(0000285)
luk (administrator)
2008-10-26 14:58

If this really works I add it to the FAQ. Thanks.
(0000297)
teeler (reporter)
2008-11-18 08:52

I can't make the shell-fu work, running incrond in the foreground gives me:

"/first/half/of/String: 1: Syntax error: Unterminated quoted string
(0000298)
teeler (reporter)
2008-11-18 08:57

heh, actually, i found that in (bash, at least), doing something like

file=$*

and then when using that,

do_something "$file"

works fine, so I'm happy.
(0000327)
timb (reporter)
2009-01-03 11:14

The workaround with sh -c doesn't seem to be working for me,

the wrapping of the execution with a bash-script seems to do it.
(0000346)
isaac (reporter)
2009-03-25 05:31

The bash file=$* fix works... but it shouldn't be needed. This is quite a nasty issue. Please fix! Thanks.

Note: It is $@ as well as $#

(0000355)
idallen (reporter)
2009-06-20 14:49

Sorry about the formatting in this report; the bug reporting system
is broken. To get the multiple blanks to show and preserve formatting,
I have to use an HTML "pre" directive, which then causes the rest
of the file to be double-spaced. But at least the blanks are visible now.

> /path IN_CLOSE_WRITE /bin/sh -c '/bin/myscript "$@/@#"'

No, that won't work for all file names, especially file names containing
unusual features such as consecutive blanks, quotes, backslashes, or
newlines e.g.:

    Mom's "Good" Recipies
      are fun \ to \\ eat.

In fact, consecutive blanks in a file name will produce empty arguments
to the called script, single backslashes in the name will disappear, and
multiple backslashes in the name will compress down to a single backslash.

We can work around everything except the lost backslashes. File names
containing backslashes are impossible to handle correctly in incron since
incron throws away some of the backslashes before it calls the script.

A work-around that works for file names that do *not* contain backslashes
is to delimit the arguments with characters that can't appear in file
names, e.g.

  /path IN_CLOSE_WRITE /bin/myscript ///$@///@#///

and then recombine the multiple arguments into one and split them apart
again based on the "///" delimiters. The script fragment below will do
that for file names that don't contain backslashes or newlines:

    #!/bin/sh -u
    args=$*
    arg1=$( echo "$args" | sed -e 's:^///::' -e 's:[/]//.*::' )
    arg2=$( echo "$args" | sed -e 's:[/]//$::' -e 's:.*///::' )
    logger -t "$0" "The actual argument is '$arg1/$arg2'"

The above work-around will handle all pathnames that do *not* contain
backslashes or newlines. Blanks and quotes and all other special characters
are fine. Using Perl or something smarter than sed to do the parsing,
we could also handle newlines correctly. Pathnames containing backslashes
cannot be handled, since incron throws away some of the backslashes.

Edit: I had to change /// to [/]// in the above expressions to stop this
comment system from mangling the expressions into hyperlinks. Please find
a better comment system that preserves blanks and doesn't mangle what I enter.

(0000357)
muellejo (reporter)
2009-06-19 17:15

I would like to use incron to convert ISO-8859 encoded files to
utf-8. This works great but if the file contains umlauts *and* spaces it fails.

It neither works like this
/tmp/test IN_CLOSE_WRITE convmv --notest -f iso-8859-1 -t utf8 $@/$#

nor like this
/tmp/test IN_CLOSE_WRITE /bin/sh -c 'convmv --notest -f iso-8859-1 -t utf8 "$@/$#"'

The log /var/log/cron shows this:

Jun 19 16:23:03 cmspap1 incrond[17967]: (meth01) CMD (convmv --notest -f iso-8859-1 -t utf8 -r /tmp/test/16.06.09 Schulprojekt Christ-K�ig Schule 007.jpg)

Jun 19 16:36:49 cmspap1 incrond[17967]: (meth01) CMD (/bin/sh -c 'convmv --notest -f iso-8859-1 -t utf8 "/tmp/test/16.06.09 Schulprojekt Christ-K�ig Schule 007.jpg"')


This is an example file:

BASH-meth01@cmspap1.aschendorff.de /tmp/red# echo *
16.06.09 Schulprojekt Christ-K�ig Schule 007.jpg

BASH-meth01@cmspap1.aschendorff.de /tmp/red# echo * | file -
/dev/stdin: ISO-8859 text

BASH-meth01@cmspap1.aschendorff.de /tmp/red# echo * | xxd -c 256
0000000: 3136 2e30 362e 3039 2053 6368 756c 7072 6f6a 656b 7420 4368 7269 7374 2d4b f66e 6967 2053 6368 756c 6520 3030 372e 6a70 670a 16.06.09 Schulprojekt Christ-K.nig Schule 007.jpg.
(0000358)
idallen (reporter)
2009-06-20 14:50

muellejo: read my comment #355 on how to handle blanks.

  /path IN_CLOSE_WRITE /bin/myscript ///$@///@#///

  #!/bin/sh -u
  args=$*
  arg1=$( echo "$args" | sed -e 's:^///::' -e 's:[/]//.*::' )
  arg2=$( echo "$args" | sed -e 's:[/]//$::' -e 's:.*///::' )
  logger -t "$0" "The actual argument is '$arg1/$arg2'"

(0000359)
idallen (reporter)
2009-06-20 14:47

This comment system is a pain to use. It removes blanks and it turned my "sed" expression into a hyperlink and mangled it. I had to insert superfluous [] into the expression to hide it from the comment system.
(0000360)
luk (administrator)
2009-06-21 18:14

This bug has been fixed (thanks to Boris Lechner). This fix will be incorporated into the next release.

- Issue History
Date Modified Username Field Change
2007-11-23 12:56 cpm New Issue
2007-11-23 20:57 luk Status new => assigned
2007-11-23 20:57 luk Assigned To => luk
2008-04-06 08:50 neilm Note Added: 0000139
2008-10-23 23:47 tamasrepus Note Added: 0000283
2008-10-24 02:41 tamasrepus Note Added: 0000284
2008-10-26 14:58 luk Note Added: 0000285
2008-11-18 08:52 teeler Note Added: 0000297
2008-11-18 08:57 teeler Note Added: 0000298
2009-01-03 11:14 timb Note Added: 0000327
2009-03-25 05:18 isaac Note Added: 0000346
2009-03-25 05:31 isaac Note Edited: 0000346
2009-03-25 05:39 isaac Issue Monitored: isaac
2009-03-30 22:10 luk Priority normal => urgent
2009-03-30 22:10 luk Severity minor => major
2009-05-28 14:18 idallen Note Added: 0000355
2009-05-28 14:20 idallen Issue Monitored: idallen
2009-05-28 15:50 idallen Note Edited: 0000355
2009-05-28 15:53 idallen Note Edited: 0000355
2009-05-28 15:54 idallen Note Edited: 0000355
2009-05-28 15:55 idallen Note Edited: 0000355
2009-05-28 15:56 idallen Note Edited: 0000355
2009-06-19 17:15 muellejo Note Added: 0000357
2009-06-20 14:44 idallen Note Added: 0000358
2009-06-20 14:45 idallen Note Edited: 0000358
2009-06-20 14:47 idallen Note Added: 0000359
2009-06-20 14:49 idallen Note Edited: 0000355
2009-06-20 14:50 idallen Note Edited: 0000358
2009-06-21 18:14 luk Note Added: 0000360
2009-06-21 18:14 luk Status assigned => resolved
2009-06-21 18:14 luk Resolution open => fixed
2010-05-21 17:49 luk Status resolved => closed


Copyright © 2000 - 2010 MantisBT Group
Powered by Mantis Bugtracker