applied mingw patch from #3409
This commit is contained in:
parent
5578c6143c
commit
1bceca1099
|
@ -1547,8 +1547,21 @@ string ROSPack::getCachePath()
|
|||
}
|
||||
else
|
||||
{
|
||||
// UNIXONLY
|
||||
// Not cross-platform?
|
||||
#if defined(WIN32)
|
||||
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");
|
||||
if (ros_home)
|
||||
{
|
||||
|
@ -1563,6 +1576,7 @@ string ROSPack::getCachePath()
|
|||
}
|
||||
cache_file_name = dotros + "rospack_cache";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return cache_file_name;
|
||||
}
|
||||
|
@ -1770,7 +1784,7 @@ void ROSPack::crawl_for_packages(bool force_crawl)
|
|||
// Try to avoid repeated allocation.
|
||||
path_components.reserve(MAX_DIRECTORY_DEPTH+1);
|
||||
// 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)
|
||||
{
|
||||
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
|
||||
{
|
||||
if (!S_ISDIR(find_file_data.dwFileAttributes))
|
||||
if (find_file_data.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY ) {
|
||||
continue; // Ignore non-directories
|
||||
if (find_file_data.cFileName[0] == '.')
|
||||
}
|
||||
if (find_file_data.cFileName[0] == '.') {
|
||||
continue; // Ignore hidden directories
|
||||
}
|
||||
string child_path = cqe.path + fs_delim + string(find_file_data.cFileName);
|
||||
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];
|
||||
_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);
|
||||
#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
|
||||
snprintf(tmp_cache_path, sizeof(tmp_cache_path), "%s/.rospack_cache.XXXXXX", dirname(tmp_cache_dir));
|
||||
#endif
|
||||
#if defined(__MINGW32__)
|
||||
// There is no equivalent of mkstemp or _mktemp_s on mingw, so we resort to a slightly less secure
|
||||
// method. Could use mktemp, but as we're just redirecting to FILE anyway, tmpfile() works
|
||||
// for us.
|
||||
FILE *cache = tmpfile();
|
||||
if ( cache == NULL ) {
|
||||
fprintf(stderr,
|
||||
"[rospack] Unable to generate temporary cache file name: %u",
|
||||
errno);
|
||||
// There is no equivalent of mkstemp or _mktemp_s on mingw, so we resort to a slightly problematic
|
||||
// tempnam (above) and mktemp method. This has the miniscule chance of a race condition.
|
||||
int fd = open(tmp_cache_path, O_RDWR | O_EXCL | _O_CREAT, 0644);
|
||||
if (fd < 0)
|
||||
{
|
||||
fprintf(stderr, "[rospack] Unable to create temporary cache file %s: %u\n",
|
||||
tmp_cache_path, errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE *cache = fdopen(fd, "w");
|
||||
#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)
|
||||
{
|
||||
fprintf(stderr,
|
||||
|
|
Loading…
Reference in New Issue