Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jyaimac:libmythbase jyavenard$ cat remotefile.diff
- diff --git a/mythtv/libs/libmythbase/remotefile.cpp b/mythtv/libs/libmythbase/remotefile.cpp
- index 7ed591f..bc86309 100644
- --- a/mythtv/libs/libmythbase/remotefile.cpp
- +++ b/mythtv/libs/libmythbase/remotefile.cpp
- @@ -2,6 +2,8 @@
- using namespace std;
- #include <QUrl>
- +#include <QFile>
- +#include <QFileInfo>
- #include "mythconfig.h"
- #include "mythdb.h"
- @@ -22,8 +24,12 @@ RemoteFile::RemoteFile(const QString &_path, bool write, bool useRA,
- lock(QMutex::NonRecursive),
- controlSock(NULL), sock(NULL),
- query("QUERY_FILETRANSFER %1"),
- - writemode(write)
- + writemode(write), localFile(NULL)
- {
- + bool is_local =
- + (!path.startsWith("/dev")) &&
- + ((path.startsWith("/")) || QFile::exists(path));
- + isremote = !is_local;
- if (writemode)
- {
- usereadahead = false;
- @@ -186,12 +192,33 @@ MythSocket *RemoteFile::openSocket(bool control)
- return lsock;
- }
- +bool RemoteFile::isOpen() const
- +{
- + if (isLocal())
- + {
- + return localFile;
- + }
- + return sock && controlSock;
- +}
- +
- bool RemoteFile::Open(void)
- {
- if (isOpen())
- return true;
- QMutexLocker locker(&lock);
- +
- + if (isLocal())
- + {
- + localFile = new QFile(path);
- + if (!localFile->open(writemode ? QIODevice::WriteOnly : QIODevice::ReadOnly | QIODevice::Text))
- + {
- + delete localFile;
- + localFile = NULL;
- + return false;
- + }
- + return true;
- + }
- controlSock = openSocket(true);
- if (!controlSock)
- return false;
- @@ -210,6 +237,10 @@ bool RemoteFile::Open(void)
- bool RemoteFile::ReOpen(QString newFilename)
- {
- + if (isLocal())
- + {
- + return Open();
- + }
- lock.lock();
- if (!sock)
- {
- @@ -237,6 +268,11 @@ bool RemoteFile::ReOpen(QString newFilename)
- void RemoteFile::Close(void)
- {
- + if (isLocal())
- + {
- + delete localFile;
- + localFile = NULL;
- + }
- if (!controlSock)
- return;
- @@ -266,6 +302,14 @@ void RemoteFile::Close(void)
- bool RemoteFile::DeleteFile(const QString &url)
- {
- + bool is_local =
- + (!url.startsWith("/dev")) &&
- + ((url.startsWith("/")) || QFile::exists(url));
- + if (is_local)
- + {
- + QFile file(url);
- + return file.remove();
- + }
- bool result = false;
- QUrl qurl(url);
- QString filename = qurl.path();
- @@ -300,6 +344,13 @@ bool RemoteFile::Exists(const QString &url)
- bool RemoteFile::Exists(const QString &url, struct stat *fileinfo)
- {
- + bool is_local =
- + (!url.startsWith("/dev")) &&
- + ((url.startsWith("/")) || QFile::exists(url));
- + if (is_local)
- + {
- + return QFile::exists(url);
- + }
- QUrl qurl(url);
- QString filename = qurl.path();
- QString sgroup = qurl.userName();
- @@ -353,6 +404,13 @@ bool RemoteFile::Exists(const QString &url, struct stat *fileinfo)
- QString RemoteFile::GetFileHash(const QString &url)
- {
- + bool is_local =
- + (!url.startsWith("/dev")) &&
- + ((url.startsWith("/")) || QFile::exists(url));
- + if (is_local)
- + {
- + return url;
- + }
- QString result;
- QUrl qurl(url);
- QString filename = qurl.path();
- @@ -381,6 +439,8 @@ QString RemoteFile::GetFileHash(const QString &url)
- void RemoteFile::Reset(void)
- {
- + if (isLocal())
- + return;
- QMutexLocker locker(&lock);
- if (!sock)
- {
- @@ -394,6 +454,33 @@ long long RemoteFile::Seek(long long pos, int whence, long long curpos)
- {
- QMutexLocker locker(&lock);
- + if (isLocal())
- + {
- + if (!isOpen())
- + {
- + LOG(VB_FILE, LOG_ERR, "RemoteFile::Seek(): Called with no file opened");
- + return -1;
- + }
- + long long offset = 0LL;
- + if (whence == SEEK_SET)
- + {
- + offset = min(pos, localFile->size());
- + }
- + else if (whence == SEEK_END)
- + {
- + offset = localFile->size() + pos;
- + }
- + else if (whence == SEEK_CUR)
- + {
- + offset = localFile->pos() + pos;
- + }
- + else
- + return -1;
- + if (!localFile->seek(offset))
- + return -1;
- + return localFile->pos();
- + }
- +
- if (!sock)
- {
- LOG(VB_NETWORK, LOG_ERR, "RemoteFile::Seek(): Called with no socket");
- @@ -440,6 +527,12 @@ int RemoteFile::Write(const void *data, int size)
- "RemoteFile::Write(): Called when not in write mode");
- return -1;
- }
- + if (isLocal())
- + {
- + LOG(VB_FILE, LOG_ERR,
- + "RemoteFile::Write(): Not supported in local mode");
- + return -1;
- + }
- QMutexLocker locker(&lock);
- if (!sock)
- @@ -524,6 +617,16 @@ int RemoteFile::Read(void *data, int size)
- bool response = false;
- QMutexLocker locker(&lock);
- +
- + if (isLocal())
- + {
- + if (localFile)
- + {
- + QDataStream stream(localFile);
- + return stream.readRawData(static_cast<char*>(data), size);
- + }
- + return 0;
- + }
- if (!sock)
- {
- LOG(VB_NETWORK, LOG_ERR, "RemoteFile::Read(): Called with no socket");
- @@ -611,19 +714,35 @@ int RemoteFile::Read(void *data, int size)
- return recv;
- }
- +long long RemoteFile::GetFileSize(void) const
- +{
- + if (isLocal())
- + {
- + if (localFile)
- + return localFile->size();
- + else
- + return 0;
- + }
- + return filesize;
- +}
- +
- bool RemoteFile::SaveAs(QByteArray &data)
- {
- - if (filesize < 0)
- + long long fs = GetFileSize();
- +
- + if (fs < 0)
- return false;
- - data.resize(filesize);
- - Read(data.data(), filesize);
- + data.resize(fs);
- + Read(data.data(), fs);
- return true;
- }
- void RemoteFile::SetTimeout(bool fast)
- {
- + if (isLocal())
- + return;
- if (timeoutisfast == fast)
- return;
- @@ -649,6 +768,14 @@ void RemoteFile::SetTimeout(bool fast)
- QDateTime RemoteFile::LastModified(const QString &url)
- {
- + bool is_local =
- + (!url.startsWith("/dev")) &&
- + ((url.startsWith("/")) || QFile::exists(url));
- + if (is_local)
- + {
- + QFileInfo info(url);
- + return info.lastModified();
- + }
- QDateTime result;
- QUrl qurl(url);
- QString filename = qurl.path();
- diff --git a/mythtv/libs/libmythbase/remotefile.h b/mythtv/libs/libmythbase/remotefile.h
- index 67f72b1..da9976c 100644
- --- a/mythtv/libs/libmythbase/remotefile.h
- +++ b/mythtv/libs/libmythbase/remotefile.h
- @@ -39,10 +39,10 @@ class MBASE_PUBLIC RemoteFile
- void SetTimeout(bool fast);
- - bool isOpen(void) const
- - { return sock && controlSock; }
- - long long GetFileSize(void) const
- - { return filesize; }
- + bool isOpen(void) const;
- + bool isLocal(void) const
- + { return !isremote; }
- + long long GetFileSize(void) const;
- QStringList GetAuxiliaryFiles(void) const
- { return auxfiles; }
- @@ -70,6 +70,8 @@ class MBASE_PUBLIC RemoteFile
- QStringList possibleauxfiles;
- QStringList auxfiles;
- + bool isremote;
- + QFile *localFile;
- };
- #endif
- jyaimac:libmythbase jyavenard$
Advertisement
Add Comment
Please, Sign In to add comment