[QBS] FileInfo relativePath function

Ruslan Nigmatullin EuroElessar at yandex.ru
Thu Sep 13 23:04:05 CEST 2012


13.09.2012, 22:35, "Сергей Лопатин" <magist3r at gmail.com>:
> Hi there!
>
> I found strange issue in qbs fileinfo module:
>
> function relativePath(base, rel)
> {
>     var basel = base.split('/');
>     var rell  = rel.split('/');
>     var i = 0;
>
>     while (i < basel.length && i < rell.length && basel[i] == rell[i])
>         i++;
>
>     var j = i;
>     var r = [];
>
>     for (; i < basel.length; i++) // i really don't understand why we
> need this line
>         r.push('..');
>
>     for (; j < rell.length; j++)
>         r.push(rell[j]);
>
>     return r.join('/');
> }
>
> I get some unexpected results:
>
> print(FileInfo.relativePath(".","data/webview/terminator.png"));
> ../data/webview/terminator.png
>
> print(FileInfo.relativePath("data/","data/webview/terminator.png"));
> ../webview/terminator.png
>
> print(FileInfo.relativePath("data","data/webview/terminator.png")); //
> works fine
> webview/terminator.png
>
> I don't understand why this function returns '../'.I could just delete
> these lines:
> for (; i < basel.length; i++)
>        r.push('..');
>
> but not sure if it's right and not break anything :)
>
> Regards,
> Sergei.

The issue is that special dirs (".", "..") and unnecessary slashes are not handled correctly, I'm fixing this right now.

May be it should be handled by c++ code? It looks like duplication of QDir's fuctionality

Ruslan 



More information about the Qbs mailing list