Bug 426621

Summary: fixfiles scripts doesn't handle files with spaces properly...
Product: [Fedora] Fedora Reporter: Need Real Name <bugzilla>
Component: policycoreutilsAssignee: Daniel Walsh <dwalsh>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: 8   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Current Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-01-21 15:51:56 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Patch for fixfile none

Description Need Real Name 2007-12-23 03:19:53 UTC
Description of problem:
Dan... you're probably getting sick of my bug reports but here is another one...

If you run:
fixfiles check "File with spaces"
you get:
find: File: No such file or directory
find: with: No such file or directory
find: spaces: No such file or directory

The problem is in the loop begining: 
for d in ${DIRS}

This can be fixed by surrounding the entire 'for' loop by:
( IFS=$'\n'
...
)

You probably don't need to do this for the loop that loops on the list of
$RPMFILES since rpm packages don't typically include spaces, but it probably
wouldn't hurt to do this either.

I'm surprised though that no one else has run into this problem yet... but then
again maybe I'm more anal than most on checking individual files to see what
policy changes have been made before doing a blanket 'restore' at the root
directory level :)

Comment 1 Need Real Name 2007-12-23 16:01:14 UTC
While your at it, there are probably some other variables that should for safety
be protected with quotes -- though I am not a bash expert and it may not be
necessary.

For example:
for d in $DIRS; do find $d

You might want to quote the $d.

Comment 2 Need Real Name 2007-12-23 17:04:27 UTC
Oops... you need to change IFS also where you set DIR=$* or else it breaks
having multiple [file/dir] entries on the command line.

I did it the following 'safe' way:
    oldIFS=$IFS
    IFS=$'\n'
    DIRS=$*
    IFS=$oldIFS


Comment 3 Daniel Walsh 2007-12-31 16:28:30 UTC
I fixed a little differently so that 

fixfiles check "this is a test" /etc/dan

will work

Fixed in policycoreutils-2.0.34-4.fc8

Comment 4 Need Real Name 2007-12-31 17:22:29 UTC
OK, but...

fixfiles check "this is a file" /etc/dan

works also with my version :)

unless you are saying that you don't like the error message "find /etc/dan: No
such file or directory" which occurs even if you just type "fixfiles check /etc/dan"

Just for my education, please help me understand what I am missing. Thanks.

Comment 5 Daniel Walsh 2007-12-31 20:01:35 UTC
When I tried your fix. I was only getting one file 
"this is a file" /etc/dan

Instead of

"this is a file" 
/etc/dan

Of course I might or applied it incorrectly.

If you had an alternate fix. please send it as a patch.

Comment 6 Need Real Name 2007-12-31 20:46:41 UTC
Created attachment 290592 [details]
Patch for fixfile

I don't know my (simple) patch works perfectly well for me on a wide range of
multiple file and/or directory cases...

Comment 7 Daniel Walsh 2007-12-31 22:39:44 UTC
Ok I did not wrap the DIRS line with your change.  So maybe that is why it did
not work for me.

Comment 8 Need Real Name 2007-12-31 23:48:47 UTC
Yeah - I posted the DIRS wrap as comment #3 since I realized the same thing you
did and wrote:
"Oops... you need to change IFS also where you set DIR=$* or else it breaks
having multiple [file/dir] entries on the command line."

In any case as long as your fix works, that's good enough for me - though I like
mine because it is short and sweet :)


Comment 9 Need Real Name 2008-01-15 18:45:43 UTC
Are you planning on releasing your fixed version (or mine :) so we can close out
this bug?