Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#167 CUtil.getRelativePath(base, targetfile) fails

v1.0 (example)
closed-fixed
Curt Arnold
cpptasks (103)
5
2006-03-16
2006-01-09
Markus Wankus
No

I am using cpptasks for a compiler I wrote, and I am
using the CUtil.getRelativePath(base, targetfile)
function to compute pathnames relative to the output
folder. I have the following:

base = c:\some\folder\output
targetFile = c:\some\folder\output.extension

Now, when I call CUtil.getRelativePath(base,
targetfile) with the above values, it returns:

extension

This is obviously not right. It looks like the logic
may be flawed in the getRelativePath() function.

Discussion

  • Markus Wankus
    Markus Wankus
    2006-02-01

    Logged In: YES
    user_id=1028084

    Is this project being monitored or maintained anymore? I'd
    contribute a patch for this but I'm not sure if this is
    being maintained anymore.

    Actually, there are quite a few little bugs in CppTasks, and
    it really is not extensible enough to work around with
    actually editing/patching the source directly. It is
    basically impossible to subclass CCTask and roll my own
    logic for certain methods because it uses private internal
    variables directly almost everywhere.

    I'm considering rolling my own, much more simplified version
    from scratch simply because:

    1) I do not care about support for any compilers but my own,
    and I still can't get CppTasks to stop looking for gcc, etc.
    by default. This slows things down, and wastes memory.

    2) There are quite a few bugs that have been around for
    awhile (and I found another one today...), and I simply
    can't work around some of them from my classes.

    Before I take the plunge, what is the current status of this
    project? I'm happy to submit patches if a release was
    forthcoming, but if it won't be awhile I think I'll focus on
    something else.

     
  • Markus Wankus
    Markus Wankus
    2006-02-21

    Logged In: YES
    user_id=1028084

    For what it is worth, here is a fix to the problem:

    --- CUtil.java
    +++ CUtil.java
    @@ -250,12 +250,27 @@
    }
    } else {
    firstDifference = lastSeparator + 1;
    break;
    }
    }
    +
    + // Make sure the first difference is in fact
    due to a difference
    + // in *paths* and not a partial filename. e.g.
    if we are comparing:
    + //
    + // c:\some\path\something
    + // to
    + // c:\some\path\something.extension
    + //
    + // Then firstDifference here will end up being
    the dot before the
    + // extension. We need to rewind to the last
    separator, if we found
    + // one.
    + if (lastSeparator != -1) {
    + firstDifference = lastSeparator + 1;
    + }
    +
    StringBuffer relativePath = new StringBuffer(50);
    //
    // walk from the first difference to the end
    of the base
    // adding "../" for each separator encountered
    //
    if (canonicalBase.length() > firstDifference) {

     
  • Curt Arnold
    Curt Arnold
    2006-03-16

    • status: open --> closed-fixed
     
  • Curt Arnold
    Curt Arnold
    2006-03-16

    Logged In: YES
    user_id=27193

    Valid bug: added TestCUnit.testGetRelativePath8 in rev 1.12
    of TestCUtil.java. The suggested patch however causes
    testGetRelativePath1, testGetRelativePath3 and
    testGetRelativePath4 to fail which all test much more
    frequently encountered scenarios.

    To address the issue, I changed the normalization logic on
    the base directory to add a file separator if missing
    instead of removing one if present and making compensating
    changes later in rev 1.27 of CUtil.java.

     
  • Markus Wankus
    Markus Wankus
    2006-03-17

    Logged In: YES
    user_id=1028084

    I'd really like to see this fix, and merge it with my code -
    but it isn't checked in yet? You mention v1.27 of
    CUtil.java, and v1.2 of TestCUtil.java but they are not in CVS?

    I actually have a release tomorrow and would like to fix it
    properly if the patch I submitted is no good. Can you email
    me the changes, or check them in?

    Thanks,

    Mark.

     
  • Curt Arnold
    Curt Arnold
    2006-03-17

    Logged In: YES
    user_id=27193

    They are checked in, but it takes a while for the public
    anonymous CVS to be updated from the developer CVS. Will
    email them to you.