私は smb:// 接続をマウントする際にこの機能を持っています。私の状態ではないエラーが発生した場合はどうなりますか。マウントが成功したかどうかを判断するより良い方法はありますか? ubuntu 11.04とqt 4.7.3を使用しています
bool mwDM::mountFolder()
{
QString smbUsername,smbPassword,serverPath,mountPath;
QProcess connectSamba;
QString terminalCommand,linuxPassword;
QDir dir("/mnt/backup");
smbUsername=ReadINIStr(iniPath,"Server","Username","");
smbPassword=ReadINIStr(iniPath,"Server","Password","");
serverPath=ReadINIStr(iniPath,"Server","Hostname","");
serverPath="//" + serverPath;
mountPath="/mnt/backup";
linuxPassword=ReadINIStr(iniPath,"Server","AdminPassword","");
terminalCommand="echo "+linuxPassword+" | sudo -S mount -t cifs -o username="+smbUsername+",password="+smbPassword+" "+serverPath+ " "+mountPath;
connectSamba.start("sh",QStringList() << "-c" << terminalCommand );
if(!connectSamba.waitForStarted())
{
LogWrite("Failed to start mount command", Qt::red);
}
if(!connectSamba.waitForFinished() )
{
LogWrite("Failed to finish mount command", Qt::red);
}
QString connectSamba_stderr = connectSamba.readAllStandardError();
qDebug() << "connectSamba_stderr" << connectSamba_stderr;
if(connectSamba_stderr.contains("is not a valid block device"))
{
LogWrite("Hostname is invalid", Qt::red);
return false;
}
else if(connectSamba_stderr.contains("3 incorrect password attempts"))
{
LogWrite("Admin password is incorrect", Qt::red);
return false;
}
else if(connectSamba_stderr.contains("wrong fs type, bad option, bad superblock on"))
{
LogWrite("Hostname is invalid", Qt::red);
return false;
}
else if(connectSamba_stderr.contains("Invalid argument"))
{
LogWrite("Mount error(22): Invalid argument", Qt::red);
return false;
}
else if(!dir.exists())
{
LogWrite("Directory doesn't exists", Qt::red);
return false;
}
else
{
return true;
}
}