Salome HOME
projects
/
modules
/
kernel.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[EDF30062] : Steering proxy threshold/directory without environement considerations...
[modules/kernel.git]
/
src
/
Basics
/
Basics_DirUtils.cxx
diff --git
a/src/Basics/Basics_DirUtils.cxx
b/src/Basics/Basics_DirUtils.cxx
index dee7639dac87a37de04cf43b31e077c8d437849a..57393623f4a4baa7d25e9a9bd5b96dca83be5b86 100644
(file)
--- a/
src/Basics/Basics_DirUtils.cxx
+++ b/
src/Basics/Basics_DirUtils.cxx
@@
-1,4
+1,4
@@
-// Copyright (C) 2007-202
0 CEA/DEN, EDF R&D
, OPEN CASCADE
+// Copyright (C) 2007-202
4 CEA, EDF
, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@@
-30,15
+30,16
@@
#include <algorithm>
#ifndef WIN32
#include <algorithm>
#ifndef WIN32
-#
include <sys/stat.h>
-#
include <dirent.h>
-#
include <unistd.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
#else
#include <io.h>
#define F_OK 0
#define access _access
#else
#include <io.h>
#define F_OK 0
#define access _access
-# include <windows.h>
-# include <time.h>
+#include <windows.h>
+#include <time.h>
+#include <process.h>
#endif
#ifdef WIN32
#endif
#ifdef WIN32
@@
-55,12
+56,12
@@
namespace Kernel_Utils
{
std::string tmp_str = file_path;
auto pos = file_path.rfind( _separator_ );
{
std::string tmp_str = file_path;
auto pos = file_path.rfind( _separator_ );
- if ( pos
>= 0
)
- tmp_str = pos <
(int)
file_path.size()-1 ? file_path.substr( pos+1 ) : "";
+ if ( pos
!= std::string::npos
)
+ tmp_str = pos < file_path.size()-1 ? file_path.substr( pos+1 ) : "";
pos = tmp_str.rfind( _extension_ );
pos = tmp_str.rfind( _extension_ );
- if( !with_extension && pos
>= 0
)
- tmp_str = pos <
(int)
tmp_str.size()-1 ? tmp_str.substr( 0, pos ) : "";
+ if( !with_extension && pos
!= std::string::npos
)
+ tmp_str = pos < tmp_str.size()-1 ? tmp_str.substr( 0, pos ) : "";
return tmp_str;
}
return tmp_str;
}
@@
-68,8
+69,8
@@
namespace Kernel_Utils
std::string GetDirName( const std::string& file_path )
{
auto pos = file_path.rfind( _separator_ );
std::string GetDirName( const std::string& file_path )
{
auto pos = file_path.rfind( _separator_ );
- if ( pos
>= 0
)
- return pos <
(int)
file_path.size()-1 ? file_path.substr(0, pos ) : "";
+ if ( pos
!= std::string::npos
)
+ return pos < file_path.size()-1 ? file_path.substr(0, pos ) : "";
return std::string(".");
}
return std::string(".");
}
@@
-79,7
+80,7
@@
namespace Kernel_Utils
std::wstring w_tmp_path_env = utf8_decode_s( tmp_path_env );
wchar_t* val = _wgetenv( w_tmp_path_env.c_str() );
std::string dir = val ? utf8_encode_s(val) : "";
std::wstring w_tmp_path_env = utf8_decode_s( tmp_path_env );
wchar_t* val = _wgetenv( w_tmp_path_env.c_str() );
std::string dir = val ? utf8_encode_s(val) : "";
-#else
+#else
char* val = getenv( tmp_path_env.c_str() );
std::string dir = val ? val : "";
#endif
char* val = getenv( tmp_path_env.c_str() );
std::string dir = val ? val : "";
#endif
@@
-130,7
+131,13
@@
namespace Kernel_Utils
aTmpDir += aSubDir; //Get RND sub directory
aTmpDir += aSubDir; //Get RND sub directory
- std::string aDir = aTmpDir;
+#ifdef WIN32
+ int pid = _getpid();
+#else
+ int pid = getpid();
+#endif
+
+ std::string aDir = aTmpDir + std::to_string(pid) + "_";
for ( aRND = 0; IsExists( aDir ); aRND++ )
{
for ( aRND = 0; IsExists( aDir ); aRND++ )
{
@@
-140,7
+147,7
@@
namespace Kernel_Utils
if ( aDir.back() != _separator_ ) aDir += _separator_;
if ( aDir.back() != _separator_ ) aDir += _separator_;
-#ifdef WIN32
+#ifdef WIN32
#ifdef UNICODE
std::wstring aDirToCreate = utf8_decode_s(aDir);
#else
#ifdef UNICODE
std::wstring aDirToCreate = utf8_decode_s(aDir);
#else
@@
-165,7
+172,7
@@
namespace Kernel_Utils
//============================================================================
// function : GetTempFileName
// purpose : Returns the unique temporary file name without any extension /tmp/something/file for Unix or c:\something\file for WIN32
//============================================================================
// function : GetTempFileName
// purpose : Returns the unique temporary file name without any extension /tmp/something/file for Unix or c:\something\file for WIN32
- //============================================================================
+ //============================================================================
std::string GetTmpFileName()
{
std::string tmpDir = GetTmpDir();
std::string GetTmpFileName()
{
std::string tmpDir = GetTmpDir();
@@
-177,7
+184,7
@@
namespace Kernel_Utils
sprintf(buffer, "%d", aRND);
std::string aSubDir(buffer);
if(aSubDir.size() <= 1) aSubDir = std::string("123409876");
sprintf(buffer, "%d", aRND);
std::string aSubDir(buffer);
if(aSubDir.size() <= 1) aSubDir = std::string("123409876");
-
+
aFilePath = tmpDir;
for(aRND = 0; IsExists(aFilePath); aRND++) {
sprintf(buffer, "%d", aRND);
aFilePath = tmpDir;
for(aRND = 0; IsExists(aFilePath); aRND++) {
sprintf(buffer, "%d", aRND);
@@
-186,12
+193,12
@@
namespace Kernel_Utils
}
return aFilePath;
}
}
return aFilePath;
}
-
+
std::string AddExtension( const std::string& name )
{
std::string tmp_str = name;
auto pos = tmp_str.rfind( _extension_ );
std::string AddExtension( const std::string& name )
{
std::string tmp_str = name;
auto pos = tmp_str.rfind( _extension_ );
- if( pos
< 0
)
+ if( pos
== std::string::npos
)
return tmp_str.append( _extension_ );
return tmp_str;
}
return tmp_str.append( _extension_ );
return tmp_str;
}
@@
-199,13
+206,13
@@
namespace Kernel_Utils
//============================================================================
// function : IsExists
// purpose : Returns True(False) if the path (not)exists
//============================================================================
// function : IsExists
// purpose : Returns True(False) if the path (not)exists
- //============================================================================
- bool IsExists(const std::string& thePath)
+ //============================================================================
+ bool IsExists(const std::string& thePath)
{
#if defined WIN32 && defined UNICODE
int status = _waccess( utf8_decode_s( thePath).c_str(), F_OK );
#else
{
#if defined WIN32 && defined UNICODE
int status = _waccess( utf8_decode_s( thePath).c_str(), F_OK );
#else
- int status = access ( thePath.c_str() , F_OK );
+ int status = access ( thePath.c_str() , F_OK );
#endif
if (status != 0) return false;
return true;
#endif
if (status != 0) return false;
return true;
@@
-214,7
+221,7
@@
namespace Kernel_Utils
//============================================================================
// function : IsWritable
// purpose : Returns True(False) if the path is (not) writable
//============================================================================
// function : IsWritable
// purpose : Returns True(False) if the path is (not) writable
- //============================================================================
+ //============================================================================
bool IsWritable(const std::string& thePath)
{
#ifdef WIN32
bool IsWritable(const std::string& thePath)
{
#ifdef WIN32
@@
-228,8
+235,8
@@
namespace Kernel_Utils
return false;
}
}
return false;
}
}
-#else
- int status = access(thePath.c_str(),W_OK);
+#else
+ int status = access(thePath.c_str(),W_OK);
if (status != 0) return false;
#endif
return true;
if (status != 0) return false;
#endif
return true;
@@
-239,7
+246,7
@@
namespace Kernel_Utils
//============================================================================
// function : GetDirByPath
// purpose : Returns directory by path and converts it to native system format
//============================================================================
// function : GetDirByPath
// purpose : Returns directory by path and converts it to native system format
- //============================================================================
+ //============================================================================
std::string GetDirByPath(const std::string& thePath)
{
if (thePath.empty())
std::string GetDirByPath(const std::string& thePath)
{
if (thePath.empty())
@@
-293,8
+300,8
@@
namespace Kernel_Utils
// function : IsEmptyDir
// purpose : Returns True(False) if the path (not) empty
// Also returns False if the path is not valid
// function : IsEmptyDir
// purpose : Returns True(False) if the path (not) empty
// Also returns False if the path is not valid
- //============================================================================
- bool IsEmptyDir(const std::string& thePath)
+ //============================================================================
+ bool IsEmptyDir(const std::string& thePath)
{
if ( thePath.empty() || !IsExists(thePath))
return false;
{
if ( thePath.empty() || !IsExists(thePath))
return false;
@@
-343,9
+350,9
@@
namespace Kernel_Utils
}
//============================================================================
}
//============================================================================
- // function : BackSlashToSlash
+ // function : BackSlashToSlash
// purpose : Convert back slash to slash
// purpose : Convert back slash to slash
- //============================================================================
+ //============================================================================
std::string BackSlashToSlash(const std::string& path) {
std::string res = path;
std::replace(res.begin(), res.end(), '\\', '/');
std::string BackSlashToSlash(const std::string& path) {
std::string res = path;
std::replace(res.begin(), res.end(), '\\', '/');
@@
-354,14
+361,14
@@
namespace Kernel_Utils
//============================================================================
//============================================================================
- // function : BackSlashToSlash
+ // function : BackSlashToSlash
// purpose : Convert back slash to slash
// purpose : Convert back slash to slash
- //============================================================================
+ //============================================================================
std::string HomePath() {
#ifdef WIN32
std::string homedir = getenv("USERPROFILE");
#else
std::string HomePath() {
#ifdef WIN32
std::string homedir = getenv("USERPROFILE");
#else
- std::string homedir = getenv("HOME");
+ std::string homedir = getenv("HOME");
#endif
return homedir;
}
#endif
return homedir;
}