Author Topic: ProjectFile and filenames containing a \ on Linux  (Read 5062 times)

Offline Der Meister

  • Regular
  • ***
  • Posts: 307
ProjectFile and filenames containing a \ on Linux
« on: December 22, 2005, 03:02:59 pm »
As I described here I got problems with the Code Statistics Plugin and a project importet from Microsoft Visual Studio .NET 2003 on Linux.
Seems as I now discovered the problem. It is not really a problem of the Code Statistics plugin (although the issue I described in the bug report could be solved there) but the problem lies in the Code::Blocks SDK. The problematic class is 'ProjectFile' and especially its member 'file', which is from type 'wxFileName'. This class uses different path formats for the filenames and the format defaults to the format which is used on the specific plattform, that means it will allow '/' als path delimiter on linux/etc. and '/' and '\\' on Windows. That means: If the filename contains a '\\' on Linux (which is the case for all filenames of the project I imported and even for all filenames of Code::Blocks, thus the plugin didn't even work with the Code::Blocks sources.) wxFileName::FileExists will return false even if the file exists. Therefore the Code Statistics plugin will ignore all files and then produce this silly output.
As a consequence the problem with the plugin can be easily solved if the wxFileName instance in the plugin uses wxPATH_DOS as format. I wrote a patch with this change and it seems to work quite well (I'll submit the patch to sourceforge later).

But I don't really like this solution as it only reduces the symptoms and not the real problem. The 'file' member of 'ProjectFile' still uses wxPATH_NATIVE as path-format, that means the problem could easily appear again on another place. Even more problematic: 'file' is a public member of 'ProjectFile'. That is not only bad style (my opinion ;) ) but makes it hard or even impossible to control it and to make sure that it uses the right style or contains only pathnames which are correct according to the current style. As I didn't write this class I don't know why it was written in that way - maybe there is even a good reason for this. But as there will be bigger changes to sdk in the near future I think we should think about a possible re-design of this class, too.
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand.
Real Programmers don't write in BASIC. Actually, no programmers write in BASIC, after the age of 12.

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: ProjectFile and filenames containing a \ on Linux
« Reply #1 on: December 22, 2005, 03:40:30 pm »
Hmm... since Windows accepts paths with / instead of \ separators, maybe it'd be a good idea to save the paths in / separated form in the project files and convert to \ on on output/load? (and convert input back on entering/saving resp. of course)
That should make project files more portable, and the file format more uniform over different platforms.

Or maybe just add a property in the project file indicating in which format it was saved? (Which would then be the native format of the system it was saved on)
Since wxPathFormat is an enum, it could be saved as an int and cast back to wxPathFormat on load, then used as a parameter to wxFilename calls to normalize the path to the native path format? (If they're not normally loaded into a wxFileName, only do this if the format is not the native one).
This method would still make project files more portable, but would likely create extra differences if a project is worked on on platforms with different path formats though. Not nice if you want to use SVN diff to see what was changed in the project file on a different platform :(.
By the way, I presume wxFileName::GetFormat() returns something other than wxPATH_NATIVE, but does anyone know what the defaulted parameter is for? It doesn't make sense to me.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: ProjectFile and filenames containing a \ on Linux
« Reply #2 on: December 22, 2005, 03:49:11 pm »
Hmm... since Windows accepts paths with / instead of \ separators, maybe it'd be a good idea to save the paths in / separated form in the project files and convert to \ on on output/load?
We tried that... this breaks UNC paths and does not work on Windows98/ME.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: ProjectFile and filenames containing a \ on Linux
« Reply #3 on: December 22, 2005, 04:56:36 pm »
Hmm... since Windows accepts paths with / instead of \ separators, maybe it'd be a good idea to save the paths in / separated form in the project files and convert to \ on on output/load?
We tried that... this breaks UNC paths and does not work on Windows98/ME.

Not even if you use wxFileName(path) (possibly with an explicit wxPATH_UNIX second argument if necessary) to convert it when you're loading the project file? Or just a dumb wxString(path).Replace("/", "\\") (#ifdef __WXMSW__ only, of course)?

...

I suppose you could always XML-ify it a bit more:
Code
<Path><PathPart>src</PathPart><PathPart>file.cpp</PathPart></Path>
(j/k :P)