Commit 3d94b5c0 authored by Huff, Israel's avatar Huff, Israel
Browse files

- removed some unused member variables from SFTPSessionImpl

- added some nullptr checks to SFTPSession, SFTPFile and SFTPDir
parent 40d7cf30
Pipeline #100262 failed with stages
in 5 minutes and 10 seconds
......@@ -122,22 +122,14 @@ class SFTPSessionImpl
{
public:
sftp_session sftpSession = nullptr;
int errorCode = SSH_OK;
const char* errorMsg = nullptr;
explicit SFTPSessionImpl(ssh_session sshSession)
{
sftpSession = sftp_new(sshSession);
if (nullptr == sftpSession)
{
errorCode = SSH_ERROR;
errorMsg = ssh_get_error(sshSession);
return;
}
if (nullptr == sftpSession) return;
// SSH_OK, SSH_ERROR, etc; see libssh.h
int rc = sftp_init(sftpSession);
if (rc != SSH_OK)
{
errorCode = sftp_get_error(sftpSession);
sftp_free(sftpSession);
sftpSession = nullptr;
}
......@@ -158,38 +150,32 @@ SFTPSession::~SFTPSession()
bool SFTPSession::mkdir(QString dirName)
{
if (nullptr == p->sftpSession) return false;
// S_IRWXU: create dir with read/write/exec by owner only
int rc = sftp_mkdir(p->sftpSession, dirName.toStdString().c_str(), S_IRWXU);
if (rc != SSH_OK)
{
if (sftp_get_error(p->sftpSession) != SSH_FX_FILE_ALREADY_EXISTS)
{
p->errorCode = SSH_ERROR;
p->errorMsg = ssh_get_error(p->sftpSession);
return false;
}
}
return true;
}
bool SFTPSession::rmdir(QString dirName)
{
if (nullptr == p->sftpSession) return false;
int rc = sftp_rmdir(p->sftpSession, dirName.toStdString().c_str());
if (rc != SSH_OK)
{
if (sftp_get_error(p->sftpSession) != SSH_FX_FILE_ALREADY_EXISTS)
{
p->errorCode = SSH_ERROR;
p->errorMsg = ssh_get_error(p->sftpSession);
return false;
}
}
return true;
}
SFTPFile* SFTPSession::openFile(QString filename, int accessType)
{
return new SFTPFile(*this, filename.toStdString().c_str(), accessType);
return new SFTPFile(this, filename.toStdString().c_str(), accessType);
}
SFTPDir* SFTPSession::openDir(QString dirName)
......@@ -198,7 +184,7 @@ SFTPDir* SFTPSession::openDir(QString dirName)
return sftpDir;
}
QString SFTPSession::error() { return p->errorMsg; }
QString SFTPSession::error() { return QString(ssh_get_error(p->sftpSession)); }
QString SFTPSession::canonicalize(QString path)
{
......@@ -223,6 +209,7 @@ class SFTPFileImpl
explicit SFTPFileImpl(sftp_session sftpSession, QString filename,
int accessType)
{
if (nullptr == sftpSession) return;
file = sftp_open(sftpSession, filename.toStdString().c_str(), accessType,
S_IRWXU);
}
......@@ -233,9 +220,9 @@ class SFTPFileImpl
}
}; // class SFTPFileImpl
SFTPFile::SFTPFile(SFTPSession& sftpSession, QString filename, int accessType)
SFTPFile::SFTPFile(SFTPSession* sftpSession, QString filename, int accessType)
{
p = new SFTPFileImpl(sftpSession.p->sftpSession, filename, accessType);
p = new SFTPFileImpl(sftpSession->p->sftpSession, filename, accessType);
}
SFTPFile::~SFTPFile()
......@@ -306,6 +293,7 @@ class SFTPDirImpl
explicit SFTPDirImpl(sftp_session sftpSession, QString dirName)
{
if (nullptr == sftpSession) return;
dir = sftp_opendir(sftpSession, dirName.toStdString().c_str());
sftp = sftpSession;
}
......
......@@ -347,7 +347,7 @@ class RSM_PUBLIC SFTPFile
SFTPFileImpl* p;
public:
SFTPFile(SFTPSession& sftpSession, QString filename, int accessType);
SFTPFile(SFTPSession* sftpSession, QString filename, int accessType);
~SFTPFile();
bool isOpen();
ssize_t write(QString str);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment