<font color="#000000"><font face="arial,helvetica,sans-serif">Well, the correctness of the include-directive can definitely be questioned, I didn't write it, I was just the one who ran into a problem with it :P<br><br>
Regardless, in the general case I don't think that file:path_open(["path1", "path2"], "foo/bar", SomeMode) should not fail just because path1 happens to contain a regular file called foo.<br>
<br>Thomas<br></font></font><br><div class="gmail_quote">On Fri, Oct 26, 2012 at 3:17 PM, Alexander Harju <span dir="ltr"><<a href="mailto:alexander.harju@mobilearts.com" target="_blank">alexander.harju@mobilearts.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>I don't think this is a bug at all.</div><div>-include(...) should not contain a path.</div><div>Use compile:file("one.erl", [{i, Dir},...])</div>
<div><br></div><div>// Alex</div><div><br></div><div><div>
<div><div><div class="gmail_quote"><div><div class="h5">On Fri, Oct 26, 2012 at 1:39 PM, Thomas Järvstrand <span dir="ltr"><<a href="mailto:thomas.jarvstrand@klarna.com" target="_blank">thomas.jarvstrand@klarna.com</a>></span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><font color="#000000"><font face="arial,helvetica,sans-serif">Figured out what the error was and this is definitely a bug.<br>

<br>Steps to reproduce:<br>Create a "project" with the following tree<br><b><span style="font-family:courier new,monospace"><br>
</span></b></font></font><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><font color="#000000"><font face="arial,helvetica,sans-serif"><b><span style="font-family:courier new,monospace"> test-project $ tree</span></b></font></font><br>


<font color="#000000"><font face="arial,helvetica,sans-serif"><b><span style="font-family:courier new,monospace">.</span></b></font></font><br><font color="#000000"><font face="arial,helvetica,sans-serif"><b><span style="font-family:courier new,monospace">|-- include</span></b></font></font><br>


<font color="#000000"><font face="arial,helvetica,sans-serif"><b><span style="font-family:courier new,monospace">|   `-- f.hrl</span></b></font></font><br><font color="#000000"><font face="arial,helvetica,sans-serif"><b><span style="font-family:courier new,monospace">`-- src</span></b></font></font><br>


<font color="#000000"><font face="arial,helvetica,sans-serif"><b><span style="font-family:courier new,monospace">    `-- one.erl</span></b></font></font><br></blockquote><font color="#000000"><font face="arial,helvetica,sans-serif"><br>


f.hrl:<br></font></font><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><font color="#000000"><font face="arial,helvetica,sans-serif"><span style="font-family:courier new,monospace"><b>-define(foo, foo).</b></span></font></font><br>


</blockquote><font color="#000000"><font face="arial,helvetica,sans-serif"><br>one.erl:<br></font></font><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">


<span style="font-family:courier new,monospace"><b><font color="#000000">-module(one).</font><br><font color="#000000">-include("../include/f.hrl").</font><br><font color="#000000">one() -> ?hej.</font></b></span><br>


</blockquote><div><br>Now:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><b><span style="font-family:courier new,monospace"> src $ cd test-project/<br>


 test-project $ touch ../include<br> test-project $ erl<br>...<br>1> c("src/one.erl").<br>src/one.erl:2: can't find include file "../include/f.hrl"<br>src/one.erl:3: undefined macro 'foo'<br>


error<br></span></b></blockquote> <br></div><font color="#000000"><font face="arial,helvetica,sans-serif">So, this fails because a component of the filename relative to cwd is not a directory, whereas relative to the location of the source-file, it would be a directory.<span><font color="#888888"><br>


<br>Thomas<br></font></span></font></font><div><div><br><div class="gmail_quote">On Fri, Oct 26, 2012 at 11:58 AM, Thomas Järvstrand <span dir="ltr"><<a href="mailto:thomas.jarvstrand@klarna.com" target="_blank">thomas.jarvstrand@klarna.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><font color="#000000"><font face="arial,helvetica,sans-serif">Hi!<br><br>from the file-module:<br></font></font><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">



<b><span style="font-family:courier new,monospace"><font color="#000000">path_open_first([Path|Rest], Name, Mode, LastError) -></font><br><font color="#000000">    case file_name(Path) of</font><br><font color="#000000">    {error, _} = Error -></font><br>



<font color="#000000">        Error;</font><br><font color="#000000">    FilePath -></font><br><font color="#000000">        FileName = fname_join(FilePath, Name),</font><br><font color="#000000">        case open(FileName, Mode) of</font><br>



<font color="#000000">        {ok, Fd} -></font><br><font color="#000000">            {ok, Fd, FileName};</font><br><font color="#000000">        {error, enoent} -></font><br><font color="#000000">            path_open_first(Rest, Name, Mode, LastError);</font><br>



<font color="#000000">        Error -></font><br><font color="#000000">            Error</font><br><font color="#000000">        end</font><br><font color="#000000">    end;</font></span></b><br></blockquote><div><br>


For some reason that I haven't deduced yet, my os seems to return enotdir instead of enoent when resolving a relative include. Compiling module with include-directives relative to the source in the shell will result in the call file:path_open([".", "path/to/src.erl"],"../../../relative/path/to/include", [read]), which fails because the second path in the list is never tried due to file:open/2 returning enotdir.<br>



<br>I have not yet figured out why I get this return value from the c-code, but shouldn't this be more permissive regardless? I feel that at in addition to enoent there should at least be support for eisdir and enotdir.<br>



<br>Regards<span><font color="#888888"><br>Thomas<br></font></span></div>
</blockquote></div><br>
</div></div><br></div></div>_______________________________________________<br>
erlang-bugs mailing list<br>
<a href="mailto:erlang-bugs@erlang.org" target="_blank">erlang-bugs@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-bugs" target="_blank">http://erlang.org/mailman/listinfo/erlang-bugs</a><br>
<br></blockquote></div><br></div></div></div></div>
</blockquote></div><br>