This service will be undergoing maintenance at 00:00 UTC, 2016-08-01. It is expected to last about 1 hours

Bug 827647

Summary: Relative path for Drift Detections Definition Include/Excludes Path does not handle relative path alias or trailing file separator correctly
Product: [Other] RHQ Project Reporter: Larry O'Leary <loleary>
Component: driftAssignee: Jay Shaughnessy <jshaughn>
Status: CLOSED CURRENTRELEASE QA Contact: Mike Foley <mfoley>
Severity: low Docs Contact:
Priority: unspecified    
Version: 4.4CC: jshaughn
Target Milestone: ---   
Target Release: RHQ 4.5.0   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 829890 (view as bug list) Environment:
Last Closed: 2013-09-01 06:15:53 EDT Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Bug Depends On:    
Bug Blocks: 829890    

Description Larry O'Leary 2012-06-01 20:19:03 EDT
Description of problem:
When using a path for the Includes/Excludes property for a Drift Detection Definition, the drift snapshot is empty if the path entered contains a trailing file separator (/ or \). In the relative sense, all three of the following are equal:

    .
    ./
    /
    
When this is appended to a base directory/path of:

    /tmp/some

The result would become:

    /tmp/some/.
    /tmp/some/./
    /tmp/some//

Again, all three are identical, however, only the first one works:

    .  -or- /tmp/some/.

And the remaining two fail:

    ./ -or- /tmp/some/./
    /  -or- /tmp/some//
    

Version-Release number of selected component (if applicable):
4.4.0

How reproducible:
Always

Steps to Reproduce:
1.  Install JON system
2.  Create a test directory that contains a parenthesis

        cd /tmp
        mkdir -p some/dir/for/drift

3.  Add some files to the test directory

        cd /tmp
        touch some/dir/for/drift/file01.txt
        touch some/dir/for/drift/file02.txt
        echo "A file with only one line of text" >>some/dir/for/drift/file02.txt

4.  Start JON system
5.  Import platform into inventory
6.  Create a **Resource Drift Detection Definition** for the newly imported platform resource

    1.  Navigate to the platform resource's *Drift > Definitions* tab
    2.  Click the **New** button
    3.  Select **Drift Definition Template** `Template-File System`
    4.  Click **Next**
    5.  Set the following values:

        *   **Drift Definition Name:** `Relative Path Pattern`
        *   **Drift Definition Description:** `A drift path which uses a pattern that contains path alias .`
        *   **Enabled:** `Yes`
        *   **Attached to Template:** `Yes`
        *   **Drift Handling Mode:** `normal``
        *   **Pinned:** `No`
        *   **Interval:** `10`
        *   **Base Directory:**
            *   **Value Context:** `fileSystem`
            *   **Value Name:** `/tmp/some`
        *   **Includes:**
            *   **Path:** *either* `./` *or* `/`
            *   **Pattern:** `dir/for/drift/**`
        *   **Excludes:** **Leave empty**

    6.  Click **Finish**

7.  Wait for drift detection to occur for the newly created drift or use **Detect Now**
    Snapshot should reflect 0

8.  Click on the **Pin** button to view the contents of the drift snapshot
  
Actual results:
The snapshot is empty

Expected results:
The snapshot should contain:
    dir/for/drift
    |-- file01.txt
    `-- file02.txt

Additional info:
When directory traversal occurs it is normal and expected that a user will include the trailing slash (/). When building the path using base directory, relative base, and file or directory pattern, special consideration should be given to what constitutes a path and the fact that drift expects it to be relative. Therefore, all of the following should be treated as the same:

    /tmp/some/.   <-- .
    /tmp/some/./  <-- ./
    /tmp/some//   <-- /
    /tmp/some/    <-- <null>
Comment 1 Jay Shaughnessy 2012-06-05 17:42:50 EDT
I agree that they *should* be equivalent but I remember the coding for this to be somewhat tricky.  We may need to instead convert all of these to just be "." at input time.
Comment 2 Jay Shaughnessy 2012-06-07 14:35:45 EDT
Master commit db072ef663ee9d9e276971e1cce9021e26cafef5
- Add support for more flexible specification of the drift base directory
in a Drift Filter.
- Add relevant tests for new features.
Comment 3 Jay Shaughnessy 2012-06-25 12:14:04 EDT
There seems to still be a problem on Linux.  Looking further.
Comment 4 Jay Shaughnessy 2012-06-25 16:47:49 EDT
master commit 00ea14c228bd08d6572d0f17ef8040e447b9a0dd

There were two ways to go here. One was to add special case handling for
the various filter paths that equate to ".".  The other was to normalize
in the Filter constructor.  Since I tried option 1 and missed a spot in my
first try to fix it, I've now opted for option 2.  The downside is only that
what the user types may get normalized to ".". But I added some more description
text to state as much. Also, existing Filter paths using "/" or "./" will
need to be updated to "." manually, but I doubt there are any out there
currently since it wasn't working.
Comment 5 Heiko W. Rupp 2013-09-01 06:15:53 EDT
Bulk closing of items that are on_qa and in old RHQ releases, which are out for a long time and where the issue has not been re-opened since.