Переписаны условия для формирования имён каталогов
This commit is contained in:
parent
d9881f92b3
commit
c503edfe49
@ -21,105 +21,109 @@ namespace filesystem {
|
||||
|
||||
MYXLIB_INLINE Paths::Paths() = default;
|
||||
|
||||
MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() // -V2008
|
||||
|
||||
MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& defaultEtcDirectory,
|
||||
const QString& defaultConstDataDirectory,
|
||||
const QString& defaultVarDataDirectory,
|
||||
const QString& defaultLogDirectory )
|
||||
{
|
||||
QFileInfo etcDirInfo { defaultEtcDirectory };
|
||||
if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() )
|
||||
{
|
||||
m_systemConfigDirectory = defaultEtcDirectory;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_systemConfigDirectory = m_userConfigDirectory;
|
||||
}
|
||||
|
||||
QFileInfo constDataDirInfo { defaultConstDataDirectory };
|
||||
if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() )
|
||||
{
|
||||
m_systemConstDataDirectory = defaultConstDataDirectory;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_systemConstDataDirectory = m_userConstDataDirectory;
|
||||
}
|
||||
|
||||
QFileInfo varDataDirInfo { defaultVarDataDirectory };
|
||||
if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() )
|
||||
{
|
||||
m_systemVarDataDirectory = defaultVarDataDirectory;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_systemVarDataDirectory = m_userVarDataDirectory;
|
||||
}
|
||||
|
||||
QFileInfo logDirInfo { defaultLogDirectory };
|
||||
if ( !logDirInfo.isDir() || !logDirInfo.isWritable() )
|
||||
{
|
||||
m_systemLogDirectory = defaultLogDirectory;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_systemLogDirectory = m_userLogDirectory;
|
||||
}
|
||||
} // Paths::setupSystemDirectories
|
||||
|
||||
|
||||
Paths::HierarchyType Paths::getHierarchyType()
|
||||
{
|
||||
QRegExp binUnityRegexp( "/s*bin/unity$" );
|
||||
QRegExp binRegexp( "/s*bin$" );
|
||||
auto binaryDir = m_executableDirectory;
|
||||
|
||||
if ( binUnityRegexp.indexIn( binaryDir ) >= 0 )
|
||||
{
|
||||
binaryDir.remove( binUnityRegexp );
|
||||
|
||||
QFileInfo etcDirInfo { binaryDir + "/etc" };
|
||||
if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo constDataDirInfo { binaryDir + "/files/data" };
|
||||
if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo varDataDirInfo { binaryDir + "/files/lib" };
|
||||
if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo logDirInfo { binaryDir + "/files/log" };
|
||||
if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
m_systemConfigDirectory = etcDirInfo.canonicalFilePath();
|
||||
m_systemConstDataDirectory = constDataDirInfo.canonicalFilePath();
|
||||
m_systemVarDataDirectory = varDataDirInfo.canonicalFilePath();
|
||||
m_systemLogDirectory = logDirInfo.canonicalFilePath();
|
||||
setupSystemDirectories( binaryDir + "/etc",
|
||||
binaryDir + "/files/data",
|
||||
binaryDir + "/files/lib",
|
||||
binaryDir + "/files/log" );
|
||||
|
||||
return ( HierarchyType::kDevelopment );
|
||||
}
|
||||
|
||||
QRegExp binRegexp( "/s*bin$" );
|
||||
if ( binRegexp.indexIn( binaryDir ) == -1 )
|
||||
{
|
||||
m_systemConstDataDirectory = m_executableDirectory;
|
||||
m_systemVarDataDirectory = m_executableDirectory;
|
||||
m_systemConfigDirectory = m_executableDirectory;
|
||||
m_systemLogDirectory = m_executableDirectory;
|
||||
|
||||
return ( HierarchyType::kFlat );
|
||||
}
|
||||
|
||||
QRegExp optRegexp( "^/opt(/|/.+/)" + m_projectName + "/" );
|
||||
|
||||
if ( optRegexp.indexIn( binaryDir ) >= 0 )
|
||||
{
|
||||
binaryDir.remove( binRegexp );
|
||||
QFileInfo etcDirInfo { binaryDir + "/etc" };
|
||||
if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo constDataDirInfo { binaryDir + "/files/data" };
|
||||
if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo varDataDirInfo { binaryDir + "/files/lib" };
|
||||
if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo logDirInfo { binaryDir + "/files/log" };
|
||||
if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
m_systemConfigDirectory = etcDirInfo.canonicalFilePath();
|
||||
m_systemConstDataDirectory = constDataDirInfo.canonicalFilePath();
|
||||
m_systemVarDataDirectory = varDataDirInfo.canonicalFilePath();
|
||||
m_systemLogDirectory = logDirInfo.canonicalFilePath();
|
||||
setupSystemDirectories( binaryDir + "/etc",
|
||||
binaryDir + "/files/data",
|
||||
binaryDir + "/files/lib",
|
||||
binaryDir + "/files/log" );
|
||||
|
||||
return ( HierarchyType::kOpt );
|
||||
}
|
||||
|
||||
if ( binaryDir.startsWith( QStringLiteral( "/usr/local" ) ) )
|
||||
{
|
||||
QFileInfo etcDirInfo { "/usr/local/etc/" + m_projectName };
|
||||
if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo constDataDirInfo { "/usr/local/share/" + m_projectName };
|
||||
if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo varDataDirInfo { "/var/lib/" + m_projectName };
|
||||
if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo logDirInfo { "/var/log/" + m_projectName };
|
||||
if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
m_systemConfigDirectory = etcDirInfo.canonicalFilePath();
|
||||
m_systemConstDataDirectory = constDataDirInfo.canonicalFilePath();
|
||||
m_systemVarDataDirectory = varDataDirInfo.canonicalFilePath();
|
||||
m_systemLogDirectory = logDirInfo.canonicalFilePath();
|
||||
setupSystemDirectories( "/usr/local/etc/" + m_projectName,
|
||||
"/usr/local/share/" + m_projectName,
|
||||
"/var/lib/" + m_projectName,
|
||||
"/var/log/" + m_projectName );
|
||||
|
||||
return ( HierarchyType::kUsr );
|
||||
}
|
||||
|
||||
if ( binaryDir.startsWith( QStringLiteral( "/usr" ) ) )
|
||||
{
|
||||
QFileInfo etcDirInfo { "/etc/" + m_projectName };
|
||||
if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo constDataDirInfo { "/usr/share/" + m_projectName };
|
||||
if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo varDataDirInfo { "/var/lib/" + m_projectName };
|
||||
if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo logDirInfo { "/var/log/" + m_projectName };
|
||||
if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
m_systemConfigDirectory = etcDirInfo.canonicalFilePath();
|
||||
m_systemConstDataDirectory = constDataDirInfo.canonicalFilePath();
|
||||
m_systemVarDataDirectory = varDataDirInfo.canonicalFilePath();
|
||||
m_systemLogDirectory = logDirInfo.canonicalFilePath();
|
||||
setupSystemDirectories( "/etc/" + m_projectName,
|
||||
"/usr/share/" + m_projectName,
|
||||
"/var/lib/" + m_projectName,
|
||||
"/var/log/" + m_projectName );
|
||||
|
||||
return ( HierarchyType::kUsr );
|
||||
}
|
||||
@ -127,44 +131,19 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType() // -V2008
|
||||
if ( binaryDir.startsWith( m_homeDirectory + "/.local/bin" ) ||
|
||||
binaryDir.startsWith( m_homeDirectory + "/bin" ) )
|
||||
{
|
||||
QFileInfo etcDirInfo { m_userConfigDirectory };
|
||||
if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo constDataDirInfo { m_userConstDataDirectory };
|
||||
if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo varDataDirInfo { m_userVarDataDirectory };
|
||||
if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo logDirInfo { m_userLogDirectory };
|
||||
if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
m_systemConfigDirectory = etcDirInfo.canonicalFilePath();
|
||||
m_systemConstDataDirectory = constDataDirInfo.canonicalFilePath();
|
||||
m_systemVarDataDirectory = varDataDirInfo.canonicalFilePath();
|
||||
m_systemLogDirectory = logDirInfo.canonicalFilePath();
|
||||
m_systemConfigDirectory = m_userConfigDirectory;
|
||||
m_systemConstDataDirectory = m_userConstDataDirectory;
|
||||
m_systemVarDataDirectory = m_userVarDataDirectory;
|
||||
m_systemLogDirectory = m_userLogDirectory;
|
||||
|
||||
return( HierarchyType::kHome );
|
||||
}
|
||||
|
||||
binaryDir.remove( binRegexp );
|
||||
|
||||
QFileInfo etcDirInfo { binaryDir + "/etc" };
|
||||
if ( !etcDirInfo.isDir() || !etcDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo constDataDirInfo { binaryDir + "/files/data" };
|
||||
if ( !constDataDirInfo.isDir() || !constDataDirInfo.isReadable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo varDataDirInfo { binaryDir + "/files/lib" };
|
||||
if ( !varDataDirInfo.isDir() || !varDataDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
QFileInfo logDirInfo { binaryDir + "/files/log" };
|
||||
if ( !logDirInfo.isDir() || !logDirInfo.isWritable() ) { return( HierarchyType::kFlat ); }
|
||||
|
||||
m_systemConfigDirectory = etcDirInfo.canonicalFilePath();
|
||||
m_systemConstDataDirectory = constDataDirInfo.canonicalFilePath();
|
||||
m_systemVarDataDirectory = varDataDirInfo.canonicalFilePath();
|
||||
m_systemLogDirectory = logDirInfo.canonicalFilePath();
|
||||
setupSystemDirectories( binaryDir + "/etc",
|
||||
binaryDir + "/files/data",
|
||||
binaryDir + "/files/lib",
|
||||
binaryDir + "/files/log" );
|
||||
|
||||
return ( HierarchyType::kDevelopment );
|
||||
} // Paths::getHierarchyType
|
||||
@ -205,14 +184,6 @@ MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& config
|
||||
|
||||
m_hierarchyType = getHierarchyType();
|
||||
|
||||
if ( m_hierarchyType == HierarchyType::kFlat )
|
||||
{
|
||||
m_systemConstDataDirectory = m_executableDirectory;
|
||||
m_systemVarDataDirectory = m_executableDirectory;
|
||||
m_systemConfigDirectory = m_executableDirectory;
|
||||
m_systemLogDirectory = m_executableDirectory;
|
||||
}
|
||||
|
||||
m_configFilePath = m_systemConfigDirectory + "/" + m_configFileName;
|
||||
|
||||
return( true );
|
||||
@ -222,11 +193,17 @@ MYXLIB_INLINE bool Paths::init( const QString& projectDir, const QString& config
|
||||
MYXLIB_INLINE bool Paths::makeDefaultDirectories()
|
||||
{
|
||||
bool status = true;
|
||||
QDir dir;
|
||||
|
||||
if (dir.mkpath( m_userConfigDirectory )) { status = false; };
|
||||
if (dir.mkpath( m_userVarDataDirectory )) { status = false; };
|
||||
if (dir.mkpath( m_userConstDataDirectory )) { status = false; };
|
||||
if (dir.mkpath( m_userLogDirectory )) { status = false; };
|
||||
if (dir.mkpath( m_systemConfigDirectory )) { status = false; };
|
||||
if (dir.mkpath( m_systemVarDataDirectory )) { status = false; };
|
||||
if (dir.mkpath( m_systemConstDataDirectory )) { status = false; };
|
||||
if (dir.mkpath( m_systemLogDirectory )) { status = false; };
|
||||
|
||||
// FIXME if ( !m_userConfigDirectory.mkpath( m_userConfigDirectory ) ) { status = false; }
|
||||
// if ( !m_userVarDataDirectory.mkpath( m_userVarDataDirectory ) ) { status = false; }
|
||||
// if ( !m_userConstDataDirectory.mkpath( m_userConstDataDirectory ) ) { status = false; }
|
||||
// if ( !m_userLogDirectory.mkpath( m_userLogDirectory ) ) { status = false; }
|
||||
return( status );
|
||||
}
|
||||
|
||||
|
@ -85,6 +85,10 @@ class Paths
|
||||
/// @brief Расширение для файла настройки
|
||||
QString m_configFileExtension;
|
||||
|
||||
void setupSystemDirectories( const QString& defaultEtcDirectory,
|
||||
const QString& defaultConstDataDirectory,
|
||||
const QString& defaultVarDataDirectory,
|
||||
const QString& defaultLogDirectory );
|
||||
HierarchyType getHierarchyType();
|
||||
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user