forked from qt-creator/qt-creator
Utils::FileUtils: Use Utils::FileName for file paths instead of QString.
Change-Id: I9ee4c0760820e9299e238c116936ce8ef140c727 Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com> Reviewed-by: Daniel Teske <daniel.teske@nokia.com> Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
This commit is contained in:
@@ -59,14 +59,14 @@ namespace Utils {
|
||||
|
||||
\return Whether the operation succeeded.
|
||||
*/
|
||||
bool FileUtils::removeRecursively(const QString &filePath, QString *error)
|
||||
bool FileUtils::removeRecursively(const FileName &filePath, QString *error)
|
||||
{
|
||||
QFileInfo fileInfo(filePath);
|
||||
QFileInfo fileInfo = filePath.toFileInfo();
|
||||
if (!fileInfo.exists() && !fileInfo.isSymLink())
|
||||
return true;
|
||||
QFile::setPermissions(filePath, fileInfo.permissions() | QFile::WriteUser);
|
||||
QFile::setPermissions(filePath.toString(), fileInfo.permissions() | QFile::WriteUser);
|
||||
if (fileInfo.isDir()) {
|
||||
QDir dir(filePath);
|
||||
QDir dir(filePath.toString());
|
||||
dir = dir.canonicalPath();
|
||||
if (dir.isRoot()) {
|
||||
if (error) {
|
||||
@@ -86,21 +86,21 @@ bool FileUtils::removeRecursively(const QString &filePath, QString *error)
|
||||
QStringList fileNames = dir.entryList(QDir::Files | QDir::Hidden
|
||||
| QDir::System | QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
foreach (const QString &fileName, fileNames) {
|
||||
if (!removeRecursively(filePath + QLatin1Char('/') + fileName, error))
|
||||
if (!removeRecursively(FileName(filePath).appendPath(fileName), error))
|
||||
return false;
|
||||
}
|
||||
if (!QDir::root().rmdir(dir.path())) {
|
||||
if (error) {
|
||||
*error = QCoreApplication::translate("Utils::FileUtils", "Failed to remove directory '%1'.")
|
||||
.arg(QDir::toNativeSeparators(filePath));
|
||||
.arg(filePath.toUserOutput());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!QFile::remove(filePath)) {
|
||||
if (!QFile::remove(filePath.toString())) {
|
||||
if (error) {
|
||||
*error = QCoreApplication::translate("Utils::FileUtils", "Failed to remove file '%1'.")
|
||||
.arg(QDir::toNativeSeparators(filePath));
|
||||
.arg(filePath.toUserOutput());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -125,36 +125,36 @@ bool FileUtils::removeRecursively(const QString &filePath, QString *error)
|
||||
|
||||
\return Whether the operation succeeded.
|
||||
*/
|
||||
bool FileUtils::copyRecursively(const QString &srcFilePath,
|
||||
const QString &tgtFilePath, QString *error)
|
||||
bool FileUtils::copyRecursively(const FileName &srcFilePath, const FileName &tgtFilePath,
|
||||
QString *error)
|
||||
{
|
||||
QFileInfo srcFileInfo(srcFilePath);
|
||||
QFileInfo srcFileInfo = srcFilePath.toFileInfo();
|
||||
if (srcFileInfo.isDir()) {
|
||||
QDir targetDir(tgtFilePath);
|
||||
QDir targetDir(tgtFilePath.toString());
|
||||
targetDir.cdUp();
|
||||
if (!targetDir.mkdir(QFileInfo(tgtFilePath).fileName())) {
|
||||
if (!targetDir.mkdir(tgtFilePath.toFileInfo().fileName())) {
|
||||
if (error) {
|
||||
*error = QCoreApplication::translate("Utils::FileUtils", "Failed to create directory '%1'.")
|
||||
.arg(QDir::toNativeSeparators(tgtFilePath));
|
||||
.arg(tgtFilePath.toUserOutput());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
QDir sourceDir(srcFilePath);
|
||||
QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
|
||||
QDir sourceDir(srcFilePath.toString());
|
||||
QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot
|
||||
| QDir::Hidden | QDir::System);
|
||||
foreach (const QString &fileName, fileNames) {
|
||||
const QString newSrcFilePath
|
||||
= srcFilePath + QLatin1Char('/') + fileName;
|
||||
const QString newTgtFilePath
|
||||
= tgtFilePath + QLatin1Char('/') + fileName;
|
||||
FileName newSrcFilePath = srcFilePath;
|
||||
newSrcFilePath.appendPath(fileName);
|
||||
FileName newTgtFilePath = tgtFilePath;
|
||||
newTgtFilePath.appendPath(fileName);
|
||||
if (!copyRecursively(newSrcFilePath, newTgtFilePath, error))
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!QFile::copy(srcFilePath, tgtFilePath)) {
|
||||
if (!QFile::copy(srcFilePath.toString(), tgtFilePath.toString())) {
|
||||
if (error) {
|
||||
*error = QCoreApplication::translate("Utils::FileUtils", "Could not copy file '%1' to '%2'.")
|
||||
.arg(QDir::toNativeSeparators(srcFilePath),
|
||||
QDir::toNativeSeparators(tgtFilePath));
|
||||
.arg(srcFilePath.toUserOutput(), tgtFilePath.toUserOutput());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -169,19 +169,16 @@ bool FileUtils::copyRecursively(const QString &srcFilePath,
|
||||
|
||||
\return Whether at least one file in \a filePath has a newer date than \a timeStamp.
|
||||
*/
|
||||
bool FileUtils::isFileNewerThan(const QString &filePath,
|
||||
const QDateTime &timeStamp)
|
||||
bool FileUtils::isFileNewerThan(const FileName &filePath, const QDateTime &timeStamp)
|
||||
{
|
||||
QFileInfo fileInfo(filePath);
|
||||
QFileInfo fileInfo = filePath.toFileInfo();
|
||||
if (!fileInfo.exists() || fileInfo.lastModified() >= timeStamp)
|
||||
return true;
|
||||
if (fileInfo.isDir()) {
|
||||
const QStringList dirContents = QDir(filePath)
|
||||
const QStringList dirContents = QDir(filePath.toString())
|
||||
.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
foreach (const QString &curFileName, dirContents) {
|
||||
const QString curFilePath
|
||||
= filePath + QLatin1Char('/') + curFileName;
|
||||
if (isFileNewerThan(curFilePath, timeStamp))
|
||||
if (isFileNewerThan(FileName(filePath).appendPath(curFileName), timeStamp))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -197,15 +194,15 @@ bool FileUtils::isFileNewerThan(const QString &filePath,
|
||||
|
||||
return Symlink target file path.
|
||||
*/
|
||||
QString FileUtils::resolveSymlinks(const QString &path)
|
||||
FileName FileUtils::resolveSymlinks(const FileName &path)
|
||||
{
|
||||
QFileInfo f(path);
|
||||
QFileInfo f = path.toFileInfo();
|
||||
int links = 16;
|
||||
while (links-- && f.isSymLink())
|
||||
f.setFile(f.symLinkTarget());
|
||||
if (links <= 0)
|
||||
return QString();
|
||||
return f.filePath();
|
||||
return FileName();
|
||||
return FileName::fromString(f.filePath());
|
||||
}
|
||||
|
||||
QByteArray FileReader::fetchQrc(const QString &fileName)
|
||||
|
||||
Reference in New Issue
Block a user