|
QGroundControl
Ground Control Station for MAVLink Drones
|
Generic file system helper utilities. More...
Functions | |
| QByteArray | readFile (const QString &filePath, QString *errorString, qint64 maxBytes) |
| size_t | optimalBufferSize (const QString &path) |
| bool | exists (const QString &path) |
| QString | joinPath (const QString &dir, const QString &name) |
| bool | ensureDirectoryExists (const QString &path) |
| bool | ensureParentExists (const QString &filePath) |
| bool | copyDirectoryRecursively (const QString &sourcePath, const QString &destPath) |
| bool | moveFileOrCopy (const QString &sourcePath, const QString &destPath) |
| bool | atomicWrite (const QString &filePath, const QByteArray &data) |
| qint64 | availableDiskSpace (const QString &path) |
| bool | hasSufficientDiskSpace (const QString &path, qint64 requiredBytes, double margin) |
| QString | toLocalPath (const QString &urlOrPath) |
| QString | toLocalPath (const QUrl &url) |
| bool | isLocalPath (const QString &urlOrPath) |
| bool | isQtResource (const QString &path) |
| QString | computeFileHash (const QString &filePath, QCryptographicHash::Algorithm algorithm) |
| QString | computeDecompressedFileHash (const QString &filePath, QCryptographicHash::Algorithm algorithm) |
| QString | computeHash (const QByteArray &data, QCryptographicHash::Algorithm algorithm) |
| bool | verifyFileHash (const QString &filePath, const QString &expectedHash, QCryptographicHash::Algorithm algorithm) |
| QString | hashAlgorithmName (QCryptographicHash::Algorithm algorithm) |
| QString | tempDirectory () |
| QString | uniqueTempPath (const QString &templateName) |
| std::unique_ptr< QTemporaryFile > | createTempFile (const QByteArray &data, const QString &templateName) |
| std::unique_ptr< QTemporaryFile > | createTempCopy (const QString &sourcePath, const QString &templateName) |
| bool | replaceFileFromTemp (QTemporaryFile *tempFile, const QString &targetPath, const QString &backupPath) |
Variables | |
| constexpr size_t | kBufferSizeMin = 16384 |
| Minimum buffer size for I/O operations. | |
| constexpr size_t | kBufferSizeMax = 131072 |
| Maximum buffer size for I/O operations. | |
| constexpr size_t | kBufferSizeDefault = 65536 |
| Default buffer size when detection unavailable. | |
| constexpr QCryptographicHash::Algorithm | kDefaultHashAlgorithm = QCryptographicHash::Sha256 |
| Default hash algorithm for checksum operations. | |
Generic file system helper utilities.
| bool QGCFileHelper::atomicWrite | ( | const QString & | filePath, |
| const QByteArray & | data | ||
| ) |
Write data to file atomically (prevents corruption on crash/power loss) Uses QSaveFile internally: writes to temp file, then atomically renames.
| filePath | Target file path |
| data | Data to write |
Definition at line 210 of file QGCFileHelper.cc.
References atomicWrite(), and ensureParentExists().
Referenced by atomicWrite().
| qint64 QGCFileHelper::availableDiskSpace | ( | const QString & | path | ) |
Get available disk space at a path
| path | Directory or file path to query |
Definition at line 245 of file QGCFileHelper.cc.
References availableDiskSpace().
Referenced by availableDiskSpace(), and hasSufficientDiskSpace().
| QString QGCFileHelper::computeDecompressedFileHash | ( | const QString & | filePath, |
| QCryptographicHash::Algorithm | algorithm = kDefaultHashAlgorithm |
||
| ) |
Compute hash of decompressed file contents Automatically decompresses .gz, .xz, .zst, .bz2, .lz4 files before hashing For uncompressed files, behaves identically to computeFileHash
| filePath | Path to file (may be compressed) |
| algorithm | Hash algorithm (default: SHA-256) |
Definition at line 410 of file QGCFileHelper.cc.
References QGCArchiveDeviceBase::close(), computeDecompressedFileHash(), computeFileHash(), QGCCompression::isCompressedFile(), and QGCDecompressDevice::open().
Referenced by computeDecompressedFileHash().
| QString QGCFileHelper::computeFileHash | ( | const QString & | filePath, |
| QCryptographicHash::Algorithm | algorithm = kDefaultHashAlgorithm |
||
| ) |
Compute hash of file contents
| filePath | Path to file (supports Qt resources) |
| algorithm | Hash algorithm (default: SHA-256) |
Definition at line 387 of file QGCFileHelper.cc.
References computeFileHash().
Referenced by computeDecompressedFileHash(), computeFileHash(), and verifyFileHash().
| QString QGCFileHelper::computeHash | ( | const QByteArray & | data, |
| QCryptographicHash::Algorithm | algorithm = kDefaultHashAlgorithm |
||
| ) |
Compute hash of data
| data | Data to hash |
| algorithm | Hash algorithm (default: SHA-256) |
Definition at line 450 of file QGCFileHelper.cc.
References computeHash().
Referenced by computeHash().
| bool QGCFileHelper::copyDirectoryRecursively | ( | const QString & | sourcePath, |
| const QString & | destPath | ||
| ) |
Copy a directory recursively to a new location
| sourcePath | Source directory path |
| destPath | Destination directory path (created if doesn't exist) |
Definition at line 136 of file QGCFileHelper.cc.
References copyDirectoryRecursively(), ensureDirectoryExists(), and joinPath().
Referenced by copyDirectoryRecursively(), and moveFileOrCopy().
| std::unique_ptr< QTemporaryFile > QGCFileHelper::createTempCopy | ( | const QString & | sourcePath, |
| const QString & | templateName = QString() |
||
| ) |
Create a temporary copy of an existing file
| sourcePath | Path to source file to copy |
| templateName | Optional file name template (e.g., "backup_XXXXXX.dat") |
Definition at line 575 of file QGCFileHelper.cc.
References createTempCopy(), and createTempFile().
Referenced by createTempCopy().
| std::unique_ptr< QTemporaryFile > QGCFileHelper::createTempFile | ( | const QByteArray & | data, |
| const QString & | templateName = QString() |
||
| ) |
Create a temporary file with specified content The file is automatically removed when the returned QTemporaryFile is destroyed
| data | Content to write to the temporary file |
| templateName | Optional file name template (e.g., "myapp_XXXXXX.json") |
Definition at line 552 of file QGCFileHelper.cc.
References createTempFile(), and tempDirectory().
Referenced by createTempCopy(), and createTempFile().
| bool QGCFileHelper::ensureDirectoryExists | ( | const QString & | path | ) |
Ensure directory exists, creating it if necessary
| path | Directory path to ensure exists |
Definition at line 122 of file QGCFileHelper.cc.
References ensureDirectoryExists().
Referenced by copyDirectoryRecursively(), ensureDirectoryExists(), ensureParentExists(), QGClibarchive::extractAnyArchive(), QGClibarchive::extractArchiveAtomic(), QGClibarchive::extractByPattern(), QGClibarchive::extractFromDevice(), QGClibarchive::extractMultipleFiles(), QGClibarchive::extractWithFilter(), and VehicleCameraControl::handleCameraCaptureStatus().
| bool QGCFileHelper::ensureParentExists | ( | const QString & | filePath | ) |
Ensure parent directory exists for a file path
| filePath | Path to a file (parent directory will be created if needed) |
Definition at line 131 of file QGCFileHelper.cc.
References ensureDirectoryExists(), and ensureParentExists().
Referenced by atomicWrite(), QGClibarchive::decompressFromDevice(), QGClibarchive::decompressSingleFile(), ensureParentExists(), QGClibarchive::extractByPattern(), QGClibarchive::extractMultipleFiles(), QGClibarchive::extractSingleFile(), QGClibarchive::extractWithFilter(), replaceFileFromTemp(), and QGCFileDownload::start().
| bool QGCFileHelper::exists | ( | const QString & | path | ) |
Check if path exists (handles Qt resources which always "exist" if valid)
| path | File path or Qt resource path (:/...) |
Definition at line 106 of file QGCFileHelper.cc.
References exists(), and isQtResource().
Referenced by QGCCompression::detectFormat(), exists(), and QGCCompression::validateFileInput().
| QString QGCFileHelper::hashAlgorithmName | ( | QCryptographicHash::Algorithm | algorithm | ) |
Get human-readable name for hash algorithm
| algorithm | Hash algorithm |
Definition at line 477 of file QGCFileHelper.cc.
References hashAlgorithmName().
Referenced by hashAlgorithmName().
| bool QGCFileHelper::hasSufficientDiskSpace | ( | const QString & | path, |
| qint64 | requiredBytes, | ||
| double | margin = 1.1 |
||
| ) |
Check if there's sufficient disk space for an operation
| path | Target directory or file path |
| requiredBytes | Bytes needed for the operation |
| margin | Extra margin multiplier (default 1.1 = 10% safety margin) |
Definition at line 266 of file QGCFileHelper.cc.
References availableDiskSpace(), and hasSufficientDiskSpace().
Referenced by QGClibarchive::extractAnyArchive(), QGClibarchive::extractArchiveAtomic(), QGClibarchive::extractWithFilter(), and hasSufficientDiskSpace().
| bool QGCFileHelper::isLocalPath | ( | const QString & | urlOrPath | ) |
Check if URL or path refers to a local file (not network resource)
| urlOrPath | URL string or filesystem path |
Definition at line 354 of file QGCFileHelper.cc.
References isLocalPath(), and isQtResource().
Referenced by isLocalPath(), and QGCFileDownload::start().
| bool QGCFileHelper::isQtResource | ( | const QString & | path | ) |
Check if path is a Qt resource path (:/ or qrc://)
| path | Path to check |
Definition at line 377 of file QGCFileHelper.cc.
References isQtResource().
Referenced by QGCCompression::detectFormatFromFile(), exists(), QGCArchiveDeviceBase::initSourceFromPath(), isLocalPath(), isQtResource(), and QGClibarchive::openArchiveForReading().
| QString QGCFileHelper::joinPath | ( | const QString & | dir, |
| const QString & | name | ||
| ) |
Join directory and filename with path separator Handles trailing slashes correctly
| dir | Directory path |
| name | File or subdirectory name |
Definition at line 111 of file QGCFileHelper.cc.
References joinPath().
Referenced by copyDirectoryRecursively(), QGClibarchive::extractArchiveAtomic(), QGClibarchive::extractByPattern(), QGClibarchive::extractMultipleFiles(), QGClibarchive::extractWithFilter(), and joinPath().
| bool QGCFileHelper::moveFileOrCopy | ( | const QString & | sourcePath, |
| const QString & | destPath | ||
| ) |
Move a file or directory, falling back to copy+delete for cross-filesystem moves
| sourcePath | Source path (file or directory) |
| destPath | Destination path |
Definition at line 173 of file QGCFileHelper.cc.
References copyDirectoryRecursively(), and moveFileOrCopy().
Referenced by moveFileOrCopy(), and replaceFileFromTemp().
| size_t QGCFileHelper::optimalBufferSize | ( | const QString & | path = QString() | ) |
Get optimal buffer size for I/O operations (platform-adaptive) Uses filesystem block size when available, with reasonable fallback
| path | Optional path to query filesystem block size (empty = use root) |
Definition at line 68 of file QGCFileHelper.cc.
References kBufferSizeDefault, kBufferSizeMax, kBufferSizeMin, and optimalBufferSize().
Referenced by QGClibarchive::openArchiveForReading(), and optimalBufferSize().
| QByteArray QGCFileHelper::readFile | ( | const QString & | filePath, |
| QString * | errorString = nullptr, |
||
| qint64 | maxBytes = 0 |
||
| ) |
Read file contents with optional automatic decompression Supports transparent decompression of .gz, .xz, .zst, .bz2, .lz4 files Uses QGCCompression::isCompressedFile() for format detection
| filePath | Path to file (may be compressed or uncompressed) |
| errorString | Output error message on failure |
| maxBytes | Maximum bytes to read (0 = unlimited, applies to decompressed size) |
Definition at line 22 of file QGCFileHelper.cc.
References QGCArchiveDeviceBase::close(), errorString, QGCCompression::isCompressedFile(), QGCDecompressDevice::open(), and readFile().
Referenced by JsonParsing::isJsonFile(), JsonHelper::openInternalQGCJsonFile(), and readFile().
| bool QGCFileHelper::replaceFileFromTemp | ( | QTemporaryFile * | tempFile, |
| const QString & | targetPath, | ||
| const QString & | backupPath = QString() |
||
| ) |
Safely replace a file using write-to-temp-then-rename pattern More control than atomicWrite - uses provided temp file
| tempFile | Open temp file with new content (will be closed) |
| targetPath | Final destination path |
| backupPath | Optional path for backup of original (empty = no backup) |
Definition at line 602 of file QGCFileHelper.cc.
References ensureParentExists(), moveFileOrCopy(), and replaceFileFromTemp().
Referenced by replaceFileFromTemp().
| QString QGCFileHelper::tempDirectory | ( | ) |
Get the system temporary directory path
Definition at line 529 of file QGCFileHelper.cc.
References tempDirectory().
Referenced by createTempFile(), tempDirectory(), and uniqueTempPath().
| QString QGCFileHelper::toLocalPath | ( | const QString & | urlOrPath | ) |
Convert URL or path string to local filesystem path Handles: file:// URLs, qrc:// URLs (-> :/), and plain paths
| urlOrPath | URL string, QUrl, or filesystem path |
Definition at line 296 of file QGCFileHelper.cc.
References toLocalPath().
Referenced by QGCFileDownload::start(), toLocalPath(), and toLocalPath().
| QString QGCFileHelper::toLocalPath | ( | const QUrl & | url | ) |
Definition at line 317 of file QGCFileHelper.cc.
References toLocalPath().
| QString QGCFileHelper::uniqueTempPath | ( | const QString & | templateName = QString() | ) |
Create a unique temporary file path without creating the file Useful for operations that need a temp path but create the file themselves
| templateName | Optional file name template (e.g., "download_XXXXXX.tmp") |
Definition at line 534 of file QGCFileHelper.cc.
References tempDirectory(), and uniqueTempPath().
Referenced by uniqueTempPath().
| bool QGCFileHelper::verifyFileHash | ( | const QString & | filePath, |
| const QString & | expectedHash, | ||
| QCryptographicHash::Algorithm | algorithm = kDefaultHashAlgorithm |
||
| ) |
Verify file matches expected hash
| filePath | Path to file |
| expectedHash | Expected hash (hex string, case-insensitive) |
| algorithm | Hash algorithm (default: SHA-256) |
Definition at line 455 of file QGCFileHelper.cc.
References computeFileHash(), and verifyFileHash().
Referenced by verifyFileHash().
|
constexpr |
Default buffer size when detection unavailable.
Definition at line 39 of file QGCFileHelper.h.
Referenced by optimalBufferSize().
|
constexpr |
Maximum buffer size for I/O operations.
Definition at line 36 of file QGCFileHelper.h.
Referenced by QGClibarchive::deviceReadCallback(), QGClibarchive::deviceSkipCallback(), QGCArchiveDeviceBase::fillBuffer(), optimalBufferSize(), and QGClibarchive::validateArchive().
|
constexpr |
Minimum buffer size for I/O operations.
Definition at line 33 of file QGCFileHelper.h.
Referenced by optimalBufferSize().
|
constexpr |
Default hash algorithm for checksum operations.
Definition at line 140 of file QGCFileHelper.h.