2 #include <QDirIterator>
5 #include <QMimeDatabase>
25 #define VFS_EPHEMERAL_MAX_READABLE 104857600
37 , _container(container)
40 _modified = QDateTime::currentDateTimeUtc();
68 QString s = QString(
"Size: %1\nModified: %2").arg(
size()).arg(
_modified.toString());
87 bool container = r->
_metadata.value(
"container").toBool(
false);
92 QStringList pl = r->
_path.split(
"/",Qt::SkipEmptyParts);
93 QString p = pl.takeFirst();
101 r->
_path = pl.join(
"/");
144 {
VFS::ERROR( QString(
"Can only append nodes of type 'VFS_ephemeral'. Unable to append '%1'.").arg(nodename), 0,
className() );
191 else return (quint64) QJsonDocument(
_data).toJson().size();
217 r->
_reason =
"Cannot list a file";
241 QMutexLocker l(&
_lock);
243 bool creating = r->
_metadata.value(
"createIfMissing").toBool(
false);
247 bool range = r->
_metadata.contains(
"range") ? true :
false;
254 VFS::WARN(
"Range request was present on non-raw VFS_ephemeral node. Range will be ignored.",0,
className());
257 if (creating && !
size())
263 _modified = QDateTime::currentDateTimeUtc();
288 QMutexLocker l(&
_lock);
292 _modified = QDateTime::currentDateTimeUtc();
308 QMutexLocker l(&
_lock);
339 QMutexLocker l(&
_lock);
343 QString method = r->
_metadata.value(
"method").toString(
"json");
347 if (method ==
"delta")
354 _modified = QDateTime::currentDateTimeUtc();
360 if (method ==
"delta")
366 _modified = QDateTime::currentDateTimeUtc();
373 r->
_reason =
"Can't apply a json diff to _raw data.";
423 r->
_reason =
"Cannot fetch range on non-raw data.";
428 QJsonObject range = r->
_metadata[
"range"].toObject();
433 if (range.contains(
"s"))
434 start = (qint64) range[
"s"].toDouble();
436 if (range.contains(
"e"))
437 end = (qint64) range[
"e"].toDouble();
441 if (start < 0 && -start <=
size) start =
size + start;
442 if (end < 0 && -end <=
size) end =
size + end;
443 if (end == 0) end =
size - 1;
447 r->
_reason = QString(
"Can't fetch range where start >= end (%1,%2)").arg(start).arg(end);
461 r->
_reason = QString(
"Can't fetch beyond the end of data. Requested bytes %1-%2").arg(start).arg(end);
466 qint64 bytes = end - start + 1;
470 QByteArray data(
_rawData.data(),(
int)bytes);
472 if (data.length() != bytes)
474 r->
_reason = QString(
"Could not read %1 bytes. Requested bytes %2-%3, but only %4 were returned.").arg(bytes).arg(start).arg(end).arg(data.length());
488 r->
_reason = QString(
"Start value is out of range. Requested bytes %1-%2").arg(start).arg(end);
#define VFS_EPHEMERAL_MAX_READABLE
static QString applyDeltaDiff(QString data, QJsonObject delta, QString trace="", QString user="server")
Apply a delta diff to a json object.
static QJsonObject applyJsonDiff(QJsonObject obj, QJsonObject diff, QString trace="", QString user="server")
Apply a json diff to a json object.
A VFS_datastore subclass for storing data directly in memory as if it was a filesystem.
void populateMetadata(QString name)
Use an incoming file type to try to populate mime type.
Q_INVOKABLE VFS_ephemeral(bool container, bool raw=false)
Create a VFS_ephemeral node.
virtual QByteArray icon()
The "disk" icon found in the VFS_icons library.
virtual void fetchRange(VFS_request *r)
Fetch a byte range within a file.
virtual VFS_node * find(VFS_request *r)
Find a node using a VFS_request.
quint64 size()
Return the size of the data in this node.
virtual void write(VFS_request *r)
Write data to this node.
virtual void metadata(VFS_request *r)
Fetch the metadata for this node.
virtual bool isContainer()
The VFS_ephemeral node is a container or a document.
virtual void ls(VFS_request *r)
List the contents of a directory.
virtual void read(VFS_request *r)
Read the contents of this node.
static QMimeDatabase _mimeDatabase
The mime database, used for metadata.
virtual VFS_node * append(QString name, VFS_node *node, bool containerCheck=true, QString user="server")
Append a VFS_ephemeral node as a child of this node.
virtual void submit(VFS_request *r)
Submit data to this node, applying the data as a diff.
virtual QString reportDetails()
Report the current cache usage.
virtual void applyDiff(VFS_request *r)
Apply a diff to this node's data.
static QString getType(QString _path, QString _default="unknownType")
Fetch the type of a file, based on path/filename.ext.
VFS_node is the base class from which all other VFS_node classes derive.
virtual VFS_node * append(QString name, VFS_node *node, bool containerCheck=true, QString user="server")
Append a VFS_node as a child of this node.
virtual void metadata(VFS_request *r)
Fetch the metadata of this node.
VFS_node * find(QString path)
Find a node by string path.
virtual QByteArray icon()
Fetch the icon for a node.
virtual void ls(VFS_request *r)
List the contents of this node.
void diff(VFS_node *origin, VFS_request *t)
Emit a diff, which will trigger notifySubscribers() for a mounted node.
QString className()
Return the class name of a node.
QMutex _lock
A recursive mutex that is local to this node.
The base class for all requests between nodes.
@ create
create a new file/path (2)
QByteArray _rawData
the request payload, but raw data
requestType _requestType
the action this request is performing or requesting
QStringList _prefixPath
the prefix elements found while searching for the target
QString _user
who initiated this request, mostly for logging
QString _reason
if something (probably bad) happened, this is the reason
QString _path
the target path remnant... the remaining path element once the request has found its target
bool _success
if the request was successfully completed
QJsonDocument _data
the request payload
QJsonObject _metadata
the request payload
static void ERROR(QString message, int level=0, QString user="server")
Send a message to the VFS::_errors VFS_stream.
static void WARN(QString message, int level=0, QString user="server")
Send a message to the VFS::_warnings VFS_stream.
setter name
a setter DOCME
QJsonObject sequenceListing(QJsonObject l, QStringList types=sequenceTypes)
Given a list of filenames and a regex list, collapse the listing to sequences when possible.