On my machine, there is a directory named srv
in my home directory which is a symlink to /srv/http
.
Right now, this is part of the directory tree of ~/srv/map
(realpath: /srv/http/map
):
.
└── assets
| └── tilesets
| └── tileset.png
└── intro.tmx
The file ~/srv/map/intro.tmx
uses ~/srv/map/assets/tilesets/tileset.png
. Therefore, when I export ~/srv/map/intro.tmx
to ~/srv/map/assets/maps/intro.json
, I'd expect the relative path in the JSON file to become ../tilesets/tileset.png
.
The current version, however, creates ../../../../../../srv/http/map/assets/tilesets/tileset.png
, which essentially makes the file kind of unusable on my target platform without messing with the values.
Could you please respect symlinks and not force realpath
?
Hmm, I couldn't immediately reproduce this problem. I've re-created the situation as follows:
file ~/srv/http/map/assets/maps/intro.json
file ~/srv/http/map/assets/tilesets/sewer_tileset.png
file ~/srv/http/map/intro.tmx
symlink ~/home/bjorn/map -> ~/srv/http/map
When I load ~/home/bjorn/map/intro.tmx
in Tiled and export it to ~/home/bjorn/map/assets/maps/intro.json
, I get a reference to sewer_tileset.png
like "image":"..\/tilesets\/sewer_tileset.png"
, which was what should happen.
However, when I open the file again, now using the Recent Files menu, it opened it from the canonical path, so the map directory from Tiled's perspective was now ~/srv/http/map/intro.tmx
and the tileset directory was ~/srv/http/map/assets/tilesets/sewer_tileset.png
. And then, when exporting I picked the location through the symbolic link, so exporting to ~/home/bjorn/map/assets/maps/intro.json
, which then yields the unwanted reference "image":"..\/..\/..\/..\/..\/srv\/http\/map\/assets\/tilesets\/sewer_tileset.png"
.
Given that I think we want the relative link to rely on symlinks and not to always use canonical paths, for reasons I commented about at #1591, maybe the fix for this issue would be to avoid saving the recent file list as canonical paths, and just use absolute paths instead?
@bjorn Interesting. I'll close #1591, as it doesn't appear to fix the core problem we're experiencing. I've already been sketching out some more symlink-related cases. It would be interesting if your proposed solution handles these cases correctly:
.
└── assets
└── intro.tmx
(scenario: no symlinks involved, solution: already covered)
.
└── assets -> symlink to /usr/share/tilesets
└── intro.tmx
(scenario: references contain symlink, solution: don't expand symlinks)
. -> symlink to ~/srv
└── assets
| └── tilesets
| └── tileset.png
└── intro.tmx
(scenario: tmx file path contains symlink, solution: only use canonical paths)
. -> symlink to ~/srv
└── assets -> symlink to /usr/share/tilesets
└── intro.tmx
(scenario: tmx file path contains symlink and references contain symlink, solution: ?)
Since in some scenarios expanding symlinks is going to cause problems, I think this solution is simply not possible. Hence I think the problem is mostly in that Tiled uses canonical paths to store its recent files list. When it wouldn't, then the user could simply be instructed to make sure to always open his files either through the symlink or not using the symlink, and never to mix these.
Thanks a lot, @bjorn! 👍