<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>al_get_path_tail changes in 5.1.5?</title>
		<link>http://www.allegro.cc/forums/view/611986</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 05 Feb 2013 19:26:59 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have upgraded from Allegro 5.0.8 to 5.1.5 and noticed this weird <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_path_tail"><span class="a">al_get_path_tail</span></a></span> issue. Here is the pseudo code that is trying to read all files in <i>C:/mydir</i> (where <i>&quot;mydir&quot;</i> has a single directory inside named <i>&quot;test&quot;</i>).
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><a href="http://www.allegro.cc/manual/ALLEGRO_FS_ENTRY"><span class="a">ALLEGRO_FS_ENTRY</span></a><span class="k3">*</span> myDir <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_fs_entry"><span class="a">al_create_fs_entry</span></a><span class="k2">(</span><span class="s">"C:\\mydir"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  2</span>
<span class="number">  3</span><span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/al_open_directory"><span class="a">al_open_directory</span></a><span class="k2">(</span>myDir<span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  4</span>
<span class="number">  5</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_FS_ENTRY"><span class="a">ALLEGRO_FS_ENTRY</span></a><span class="k3">*</span> nextFile<span class="k2">;</span>
<span class="number">  6</span>  <span class="k1">while</span> <span class="k2">(</span>nextFile <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_read_directory"><span class="a">al_read_directory</span></a><span class="k2">(</span>myDir<span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  7</span>
<span class="number">  8</span>    <span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> nextFilePath <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_fs_entry_name"><span class="a">al_get_fs_entry_name</span></a><span class="k2">(</span>nextFile<span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>
<span class="number"> 10</span>    <span class="c">// nextFilePath == "C:\\mydir\\test"</span>
<span class="number"> 11</span>
<span class="number"> 12</span>    ALLEGRO_PATH<span class="k3">*</span> nextFilePathA <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_path"><span class="a">al_create_path</span></a><span class="k2">(</span>nextFilePath<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    
<span class="number"> 14</span>    <span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> nextFileName <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_path_tail"><span class="a">al_get_path_tail</span></a><span class="k2">(</span>nextFilePathA<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>    
<span class="number"> 16</span>    <span class="c">// nextFileName == "mydir" when expecting "test"</span>
<span class="number"> 17</span>
<span class="number"> 18</span>    <a href="http://www.allegro.cc/manual/al_destroy_path"><span class="a">al_destroy_path</span></a><span class="k2">(</span>nextFilePathA<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>    <a href="http://www.allegro.cc/manual/al_destroy_fs_entry"><span class="a">al_destroy_fs_entry</span></a><span class="k2">(</span>nextFile<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>  <span class="k2">}</span>
<span class="number"> 21</span>
<span class="number"> 22</span>  <a href="http://www.allegro.cc/manual/al_close_directory"><span class="a">al_close_directory</span></a><span class="k2">(</span>myDir<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 23</span><span class="k2">}</span>
<span class="number"> 24</span>
<span class="number"> 25</span><a href="http://www.allegro.cc/manual/al_destroy_fs_entry"><span class="a">al_destroy_fs_entry</span></a><span class="k2">(</span>myDir<span class="k2">)</span><span class="k2">;</span>
</div></div><p>

In short - <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_path_tail"><span class="a">al_get_path_tail</span></a></span> does not really return the last part/tail of a path, but one above it.</p><p>Note, that I am using PhysFS addon. Is this a bug or an intended change/feature?</p><p><b>Edit:</b> Replacing <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_path"><span class="a">al_create_path</span></a></span> with <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_path_for_directory"><span class="a">al_create_path_for_directory</span></a></span> fixed the issue when reading directories. Still, I would like to understand why this change was introduced in 5.1 branch.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (simast)</author>
		<pubDate>Sun, 03 Feb 2013 17:03:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Both functions al_create_path and al_creat_path_from_directory exist since 5.0. I guess that this means that the previous behaviour was actually a bug???
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Sun, 03 Feb 2013 17:18:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/611986/976159#target">beoran</a> said:</div><div class="quote"><p>Both functions al_create_path and al_creat_path_from_directory exist since 5.0. I guess that this means that the previous behaviour was actually a bug???</p></div></div><p>

I doubt it. More likely something isn&#39;t right in 5.1. It looks like <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_path"><span class="a">al_create_path</span></a></span> is now expecting a path for directories with the end slash/separator included? If that is the case - the File-System module functions don&#39;t play well with Path module functions (as <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_fs_entry_name"><span class="a">al_get_fs_entry_name</span></a></span> is returning paths without the end directory separator included).</p><p>The PhysFS addon could also be an issue here..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (simast)</author>
		<pubDate>Sun, 03 Feb 2013 17:56:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/611986/976157#target">simast</a> said:</div><div class="quote"><p>In short - al_get_path_tail does not really return the last part/tail of a path, but one above it.</p></div></div><p>It returns the last directory in the path. If you pass in a path without a trailing slash, it interprets the last item as a filename, and if it has a trailing slash, its interpreted as a directory. I&#39;m pretty sure it&#39;s always been like that. But <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_path_for_directory"><span class="a">al_create_path_for_directory</span></a></span> was added because its quite annoying having to append a slash to a string gotten from some of the other functions all the time just to properly build an <span class="source-code">ALLEGRO_PATH</span> for a path to a directory.</p><p>As far as I can recall this behaviour hasn&#39;t changed at all. The current behaviour of treating a path without a trailing slash as a directory with a file is what I had intended from the beginning. It had been modified a couple times since I wrote it and I can&#39;t remember exactly what got changed, but I don&#39;t think that did.</p><p>Maybe it&#39;s not the best design, my main reason for separating out the filename was so we could actually provide a proper &quot;get filename&quot; function, meaning you can tell the path functions that a given path contains a filename, and you can then get it. Rather than just having the get filename function always returning the last path component, even if its actually intended to be a directory.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 03 Feb 2013 21:43:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi Thomas,</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I&#39;m pretty sure it&#39;s always been like that. As far as I can recall this behavior hasn&#39;t changed at all.
</p></div></div><p>

I have never had issues with that part of my code - it only started behaving differently when I have upgraded from 5.0.8 to 5.1.5. There must be some sort of a change somewhere there.</p><p>I think the real problem is illustrated with this code below:</p><div class="source-code snippet"><div class="inner"><pre>  <span class="c">// Test Filesystem API</span>
  <a href="http://www.allegro.cc/manual/ALLEGRO_FS_ENTRY"><span class="a">ALLEGRO_FS_ENTRY</span></a><span class="k3">*</span> testFS <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_fs_entry"><span class="a">al_create_fs_entry</span></a><span class="k2">(</span><span class="s">"C:\\Windows\\"</span><span class="k2">)</span><span class="k2">;</span>
  <span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> testFSResult <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_fs_entry_name"><span class="a">al_get_fs_entry_name</span></a><span class="k2">(</span>testFS<span class="k2">)</span><span class="k2">;</span>

  <span class="c">// testFSResult is "C:\\Windows" (note the lack of trailing slash)</span>

  <span class="c">// Test Path API</span>
  ALLEGRO_PATH<span class="k3">*</span> testPath <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_path"><span class="a">al_create_path</span></a><span class="k2">(</span><span class="s">"C:\\Windows\\"</span><span class="k2">)</span><span class="k2">;</span>
  <span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> testPathResult <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_path_cstr"><span class="a">al_path_cstr</span></a><span class="k2">(</span>testPath, ALLEGRO_NATIVE_PATH_SEP<span class="k2">)</span><span class="k2">;</span>

  <span class="c">// testPathResult is "C:\\Windows\\" (with a trailing slash)</span>
</pre></div></div><p>

The Filesystem and Path APIs no longer work in tandem (the same).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (simast)</author>
		<pubDate>Tue, 05 Feb 2013 13:33:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Some things have changed, but I&#39;m not sure it was the PATH api that changed, at least not in that regard. At the very least the PATH api is acting as intended, and the FS ENTRY stuff is also acting as intended. It&#39;s a bit annoying that they don&#39;t match up.</p><p>I think the FS stuff used to append a slash on every path that was a directory on windows to work better with win32 API functions that just don&#39;t work properly if you don&#39;t. But things were tweaked at one point to change that.</p><p>I could swear there was a way to get an FS_ENTRY directly from a PATH, but I can&#39;t seem to find it atm.</p><p>I&#39;m not sure there&#39;s a way to properly fix this, as readdir just returns a bare string and you have to separately &quot;stat&quot; it to get its type.</p><p>I think if you want to keep the same behaviour you had, just always use <span class="source-code"><a href="http://www.allegro.cc/manual/al_create_path_for_directory"><span class="a">al_create_path_for_directory</span></a></span>, then you just have to ignore the filename and extension parts of the PATH api.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 05 Feb 2013 13:52:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>path.c hasn&#39;t changed since 2010.</p><p>The behaviour of al_get_fs_entry_name was changed in 5.1.5, but it was never intended to preserve exactly the string that you passed in.</p><p>On Windows we have to strip trailing slashes before calling stat(). So the ALLEGRO_FS_ENTRY had a copy of the path, but we would copy it and strip it when calling stat(). But we were stripping it incorrectly, and since ALLEGRO_FS_ENTRY has a canonical copy of the path, why not strip it once when the entry is created and do it correctly? It just happens that al_get_fs_entry_name returns a pointer to the same canonical path, which is why you see the behaviour change.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Tue, 05 Feb 2013 18:29:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I thought there might be something broken in 5.1 branch, but it looks like it&#39;s just a small BC break I can code around easily. Thanks, Peter, Thomas.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (simast)</author>
		<pubDate>Tue, 05 Feb 2013 19:26:59 +0000</pubDate>
	</item>
</rss>
