Better handling of file paths containing multiple path separators. Fix recent regression incorrectly detecting a directory on Windows when the output directory is not the current directory.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11944 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
bbf225ef63
commit
4f88d641af
3 changed files with 46 additions and 16 deletions
|
|
@ -1,6 +1,9 @@
|
|||
Version 2.0.0 (in progress)
|
||||
============================
|
||||
|
||||
2010-03-13: wsfulton
|
||||
Improve handling of file names and directories containing double/multiple path separators.
|
||||
|
||||
2010-03-10: mutandiz (Mikel Bancroft)
|
||||
[allegrocl] Use fully qualified symbol name of cl::identity in emit_defun().
|
||||
|
||||
|
|
|
|||
|
|
@ -281,20 +281,21 @@ static unsigned int decode_numbers_list(String *numlist) {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Sets the output directory for language specific (proxy) files if not set and
|
||||
// adds trailing file separator if necessary.
|
||||
// corrects the directory name and adds trailing file separator if necessary.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static void set_outdir(const String *c_wrapper_file_dir) {
|
||||
static void configure_outdir(const String *c_wrapper_file_dir) {
|
||||
|
||||
// Use the C wrapper file's directory if the output directory has not been set by user
|
||||
if (!outdir || Len(outdir) == 0)
|
||||
outdir = NewString(c_wrapper_file_dir);
|
||||
|
||||
Swig_filename_correct(outdir);
|
||||
|
||||
// Add file delimiter if not present in output directory name
|
||||
if (outdir && Len(outdir) != 0) {
|
||||
const char *outd = Char(outdir);
|
||||
if (strcmp(outd + strlen(outd) - strlen(SWIG_FILE_DELIMITER), SWIG_FILE_DELIMITER) != 0)
|
||||
Printv(outdir, SWIG_FILE_DELIMITER, NIL);
|
||||
}
|
||||
// Use the C wrapper file's directory if the output directory has not been set by user
|
||||
if (!outdir)
|
||||
outdir = NewString(c_wrapper_file_dir);
|
||||
const char *outd = Char(outdir);
|
||||
if (strcmp(outd + strlen(outd) - strlen(SWIG_FILE_DELIMITER), SWIG_FILE_DELIMITER) != 0)
|
||||
Printv(outdir, SWIG_FILE_DELIMITER, NIL);
|
||||
}
|
||||
|
||||
/* This function sets the name of the configuration file */
|
||||
|
|
@ -1221,7 +1222,7 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
|||
} else {
|
||||
Setattr(top, "outfile_h", outfile_name_h);
|
||||
}
|
||||
set_outdir(Swig_file_dirname(Getattr(top, "outfile")));
|
||||
configure_outdir(Swig_file_dirname(Getattr(top, "outfile")));
|
||||
if (Swig_contract_mode_get()) {
|
||||
Swig_contracts(top);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ char cvsroot_misc_c[] = "$Id$";
|
|||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||
#define S_ISDIR(mode) (((mode) & S_IFDIR) == S_IFDIR)
|
||||
#endif
|
||||
|
||||
static char *fake_version = 0;
|
||||
|
|
@ -142,6 +142,26 @@ String *Swig_strip_c_comments(const String *s) {
|
|||
return stripped;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* is_directory()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
static int is_directory(String *directory) {
|
||||
int last = Len(directory) - 1;
|
||||
int statres;
|
||||
struct stat st;
|
||||
char *dir = Char(directory);
|
||||
if (dir[last] == SWIG_FILE_DELIMITER[0]) {
|
||||
/* remove trailing slash - can cause S_ISDIR to fail on Windows, at least */
|
||||
dir[last] = 0;
|
||||
statres = stat(dir, &st);
|
||||
dir[last] = SWIG_FILE_DELIMITER[0];
|
||||
} else {
|
||||
statres = stat(dir, &st);
|
||||
}
|
||||
Printf(stdout, "is_directory %d %s\n", (statres == 0 && S_ISDIR(st.st_mode)), dir);
|
||||
return (statres == 0 && S_ISDIR(st.st_mode));
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Swig_new_subdirectory()
|
||||
*
|
||||
|
|
@ -154,7 +174,7 @@ String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) {
|
|||
struct stat st;
|
||||
int current_directory = basedirectory ? (Len(basedirectory) == 0 ? 1 : 0) : 0;
|
||||
|
||||
if (current_directory || ((stat(Char(basedirectory), &st) == 0) && S_ISDIR(st.st_mode))) {
|
||||
if (current_directory || is_directory(basedirectory)) {
|
||||
Iterator it;
|
||||
String *dir = basedirectory ? NewString(basedirectory) : NewString("");
|
||||
List *subdirs = Split(subdirectory, SWIG_FILE_DELIMITER[0], INT_MAX);
|
||||
|
|
@ -186,7 +206,7 @@ String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
error = NewStringf("Cannot create subdirectory %s under the base directory %s", subdirectory, basedirectory);
|
||||
error = NewStringf("Cannot create subdirectory %s under the base directory %s. Either the base does not exist as a directory or it is not readable.", subdirectory, basedirectory);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
|
@ -194,7 +214,8 @@ String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) {
|
|||
/* -----------------------------------------------------------------------------
|
||||
* Swig_filename_correct()
|
||||
*
|
||||
* Corrects filenames on non-unix systems
|
||||
* Corrects filename paths by removing duplicate delimeters and on non-unix
|
||||
* systems use the correct delimeter across the whole name.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void Swig_filename_correct(String *filename) {
|
||||
|
|
@ -207,6 +228,9 @@ void Swig_filename_correct(String *filename) {
|
|||
/* accept Windows path separator in addition to Unix path separator */
|
||||
Replaceall(filename, "\\", SWIG_FILE_DELIMITER);
|
||||
#endif
|
||||
/* remove all duplicate file name delimiters */
|
||||
while (Replaceall(filename, SWIG_FILE_DELIMITER SWIG_FILE_DELIMITER, SWIG_FILE_DELIMITER)) {
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -218,7 +242,9 @@ void Swig_filename_correct(String *filename) {
|
|||
String *Swig_filename_escape(String *filename) {
|
||||
String *adjusted_filename = Copy(filename);
|
||||
#if defined(_WIN32) /* Note not on Cygwin else filename is displayed with double '/' */
|
||||
Replaceall(adjusted_filename, "\\\\", "\\"); /* remove double '\' in case any already present */
|
||||
/* remove all double '\' in case any already present */
|
||||
while (Replaceall(adjusted_filename, "\\\\", "\\")) {
|
||||
}
|
||||
Replaceall(adjusted_filename, "\\", "\\\\");
|
||||
#endif
|
||||
return adjusted_filename;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue