applied mingw patch from #3409

This commit is contained in:
Brian Gerkey 2011-03-30 23:41:09 +00:00
parent 5578c6143c
commit 1bceca1099
1 changed files with 33 additions and 16 deletions

View File

@ -1547,8 +1547,21 @@ string ROSPack::getCachePath()
} }
else else
{ {
// UNIXONLY #if defined(WIN32)
// Not cross-platform? char* home_drive = getenv("HOMEDRIVE"); // getenv owns the memory, don't free these
char* home_path = getenv("HOMEPATH");
if ( home_drive && home_path ) {
std::string dotros = std::string(getenv("HOMEDRIVE")) + std::string(home_path) + std::string("\\.ros");
struct stat s; // maybe vista/win7 needs FindFirstFile??
if(stat(dotros.c_str(), &s))
{
if(mkdir(dotros.c_str(), 0700) != 0) {
std::cerr << "[rospack] WARNING: cannot create rospack cache directory" << std::endl;
}
}
cache_file_name = dotros + "\\rospack_cache";
}
#else // UNIX
ros_home = getenv("HOME"); ros_home = getenv("HOME");
if (ros_home) if (ros_home)
{ {
@ -1563,6 +1576,7 @@ string ROSPack::getCachePath()
} }
cache_file_name = dotros + "rospack_cache"; cache_file_name = dotros + "rospack_cache";
} }
#endif
} }
return cache_file_name; return cache_file_name;
} }
@ -1770,7 +1784,7 @@ void ROSPack::crawl_for_packages(bool force_crawl)
// Try to avoid repeated allocation. // Try to avoid repeated allocation.
path_components.reserve(MAX_DIRECTORY_DEPTH+1); path_components.reserve(MAX_DIRECTORY_DEPTH+1);
// string_split() will clear() path_components for us // string_split() will clear() path_components for us
string_split(cqe.path, path_components, "/"); string_split(cqe.path, path_components, fs_delim);
if(path_components.size() > MAX_DIRECTORY_DEPTH) if(path_components.size() > MAX_DIRECTORY_DEPTH)
{ {
fprintf(stderr,"[rospack] Exceeded maximum directory depth of %d at %s. There must be a self-referencing symlink somewhere.\n", MAX_DIRECTORY_DEPTH, cqe.path.c_str()); fprintf(stderr,"[rospack] Exceeded maximum directory depth of %d at %s. There must be a self-referencing symlink somewhere.\n", MAX_DIRECTORY_DEPTH, cqe.path.c_str());
@ -1827,10 +1841,12 @@ void ROSPack::crawl_for_packages(bool force_crawl)
do do
{ {
if (!S_ISDIR(find_file_data.dwFileAttributes)) if (find_file_data.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY ) {
continue; // Ignore non-directories continue; // Ignore non-directories
if (find_file_data.cFileName[0] == '.') }
if (find_file_data.cFileName[0] == '.') {
continue; // Ignore hidden directories continue; // Ignore hidden directories
}
string child_path = cqe.path + fs_delim + string(find_file_data.cFileName); string child_path = cqe.path + fs_delim + string(find_file_data.cFileName);
if (Package::is_package(child_path)) if (Package::is_package(child_path))
{ {
@ -1925,25 +1941,26 @@ void ROSPack::crawl_for_packages(bool force_crawl)
char full_dir[_MAX_DRIVE + _MAX_DIR]; char full_dir[_MAX_DRIVE + _MAX_DIR];
_makepath_s(full_dir, _MAX_DRIVE + _MAX_DIR, drive, dir, NULL, NULL); _makepath_s(full_dir, _MAX_DRIVE + _MAX_DIR, drive, dir, NULL, NULL);
snprintf(tmp_cache_path, sizeof(tmp_cache_path), "%s\\.rospack_cache.XXXXXX", full_dir); snprintf(tmp_cache_path, sizeof(tmp_cache_path), "%s\\.rospack_cache.XXXXXX", full_dir);
#elif defined(__MINGW32__)
char* temp_name = tempnam(dirname(tmp_cache_dir),".rospack_cache.");
snprintf(tmp_cache_path, sizeof(tmp_cache_path), temp_name);
delete temp_name;
#else #else
snprintf(tmp_cache_path, sizeof(tmp_cache_path), "%s/.rospack_cache.XXXXXX", dirname(tmp_cache_dir)); snprintf(tmp_cache_path, sizeof(tmp_cache_path), "%s/.rospack_cache.XXXXXX", dirname(tmp_cache_dir));
#endif #endif
#if defined(__MINGW32__) #if defined(__MINGW32__)
// There is no equivalent of mkstemp or _mktemp_s on mingw, so we resort to a slightly less secure // There is no equivalent of mkstemp or _mktemp_s on mingw, so we resort to a slightly problematic
// method. Could use mktemp, but as we're just redirecting to FILE anyway, tmpfile() works // tempnam (above) and mktemp method. This has the miniscule chance of a race condition.
// for us. int fd = open(tmp_cache_path, O_RDWR | O_EXCL | _O_CREAT, 0644);
FILE *cache = tmpfile(); if (fd < 0)
if ( cache == NULL ) { {
fprintf(stderr, fprintf(stderr, "[rospack] Unable to create temporary cache file %s: %u\n",
"[rospack] Unable to generate temporary cache file name: %u", tmp_cache_path, errno);
errno);
} }
else else
{ {
FILE *cache = fdopen(fd, "w");
#elif defined(WIN32) #elif defined(WIN32)
// This one is particularly nasty: on Windows, there is no equivalent of
// mkstemp, so we're stuck with the security risks of mktemp. Hopefully not a
// problem in our use cases.
if (_mktemp_s(tmp_cache_path, PATH_MAX) != 0) if (_mktemp_s(tmp_cache_path, PATH_MAX) != 0)
{ {
fprintf(stderr, fprintf(stderr,