mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0027901: Resource_Manager creates directory with insufficient permissions
Resource_Manager now sets RWXD permissions for the created directories to allow their removal. Method OSD_Directory::Build() will create intermediate directories if they do not exist yet. OSD_FileNode is corrected to clean error status in method Exists(). Tests bugs fclasses bug181_1 and bug181_2 are corrected to check existence of generated resource files; TODO is removed in bug181_2.
This commit is contained in:
@@ -43,18 +43,26 @@ TCollection_AsciiString aBuffer;
|
||||
myPath.SystemName(aBuffer);
|
||||
umask ( 0 );
|
||||
status = mkdir (aBuffer.ToCString(), (mode_t)internal_prot);
|
||||
if (status == -1)
|
||||
if (errno != EEXIST) {
|
||||
Standard_PCharacter err_message;
|
||||
|
||||
err_message = new Standard_Character [255];
|
||||
sprintf (err_message,
|
||||
"OSD_Directory::Build Directory \"%s\"",
|
||||
if (status == -1 && errno == ENOENT)
|
||||
{
|
||||
OSD_Path aSupPath = myPath;
|
||||
aSupPath.UpTrek();
|
||||
aSupPath.SetName (myPath.TrekValue (myPath.TrekLength())); // incredible, but required!
|
||||
OSD_Directory aSupDir (aSupPath);
|
||||
aSupDir.Build (Protect);
|
||||
if (aSupDir.Failed())
|
||||
{
|
||||
myError = aSupDir.myError;
|
||||
return;
|
||||
}
|
||||
status = mkdir (aBuffer.ToCString(), (mode_t)internal_prot);
|
||||
}
|
||||
if (status == -1 && errno != EEXIST) {
|
||||
Standard_Character err_message[2048];
|
||||
Sprintf (err_message, "OSD_Directory::Build Directory \"%.2000s\"",
|
||||
aBuffer.ToCString());
|
||||
|
||||
myError.SetValue(errno, Iam, err_message);
|
||||
delete err_message;
|
||||
}
|
||||
myError.SetValue (errno, Iam, err_message);
|
||||
}
|
||||
}
|
||||
|
||||
OSD_Directory OSD_Directory::BuildTemporary(){
|
||||
@@ -120,18 +128,48 @@ void OSD_Directory :: Build (const OSD_Protection& Protect) {
|
||||
if ( dirName.IsEmpty () )
|
||||
|
||||
Standard_ProgramError :: Raise ( "OSD_Directory :: Build (): incorrect call - no directory name");
|
||||
TCollection_ExtendedString dirNameW(dirName);
|
||||
if (Exists() || CreateDirectoryW (dirNameW.ToWideString(), NULL))
|
||||
{
|
||||
|
||||
Standard_Boolean isOK = Exists();
|
||||
if (! isOK)
|
||||
{
|
||||
// myError will be set to fail by Exists() if intermediate dirs do not exist
|
||||
myError.Reset();
|
||||
|
||||
// create directory if it does not exist;
|
||||
TCollection_ExtendedString dirNameW(dirName);
|
||||
if (CreateDirectoryW (dirNameW.ToWideString(), NULL))
|
||||
{
|
||||
isOK = Standard_True;
|
||||
}
|
||||
// if failed due to absence of intermediate directories, create them recursively
|
||||
else if (GetLastError() == ERROR_PATH_NOT_FOUND)
|
||||
{
|
||||
OSD_Path aSupPath = myPath;
|
||||
aSupPath.UpTrek();
|
||||
aSupPath.SetName (myPath.TrekValue (myPath.TrekLength())); // incredible, but required!
|
||||
OSD_Directory aSupDir (aSupPath);
|
||||
aSupDir.Build (Protect);
|
||||
if (aSupDir.Failed())
|
||||
{
|
||||
myError = aSupDir.myError;
|
||||
return;
|
||||
}
|
||||
isOK = (CreateDirectoryW (dirNameW.ToWideString(), NULL) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (isOK)
|
||||
{
|
||||
#ifndef OCCT_UWP
|
||||
SetProtection(Protect);
|
||||
SetProtection(Protect);
|
||||
#else
|
||||
(void)Protect;
|
||||
(void)Protect;
|
||||
#endif
|
||||
} else
|
||||
|
||||
_osd_wnt_set_error ( myError, OSD_WDirectory );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_osd_wnt_set_error ( myError, OSD_WDirectory );
|
||||
}
|
||||
} // end OSD_Directory :: Build
|
||||
|
||||
OSD_Directory OSD_Directory :: BuildTemporary () {
|
||||
|
@@ -445,7 +445,9 @@ void OSD_FileNode::SetPath ( const OSD_Path& Name ) {
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean OSD_FileNode::Exists () {
|
||||
Standard_Boolean OSD_FileNode::Exists ()
|
||||
{
|
||||
myError.Reset();
|
||||
|
||||
Standard_Boolean retVal = Standard_False;;
|
||||
TCollection_AsciiString fName;
|
||||
|
Reference in New Issue
Block a user