[Development] QTemporaryDir API

Roopesh Chander roop at forwardbias.in
Fri Nov 18 06:41:34 CET 2011


On Thu, Nov 17, 2011 at 9:54 PM, David Faure <david.faure at kdab.com> wrote:

> – konqueror sessions which are saved on disk as directories.
> I'm sure there are other similar cases of apps saving internal stuff as
> directories. Calling these "temporary" might be a bit arguable, but if the
> general agreement here is that a QDir::removeRecursive would be even worse,
> then I think this is a good compromise. It makes it clear that it's for
> app-
> created dirs (which get deleted at some point, so they are "temporary" in a
> way), not for user directories (which might be huge and contain lots of
> important data).


I wouldn't really think of dirs with saved sessions as "temporary". When
reading code like the following, I'm afraid it would appear like it's
abusing a feature of QTemporaryDir:

    // remove session
    QTemporaryDir::removeDir(userHomeDir + "/.kde/session/" + sessionId);

That said, I definitely agree that QDir::removeRecursive() might not be
appropriate, because we intend it to be not used on user-visible
directories.

A compromise could be to call the static method 'removeInternalDir'. Like
so:

    // remove session
    QDir::removeInternalDir(userHomeDir + "/.kde/session/" + sessionId);

To make it a little more harder for users to shoot themselves in the foot,
I suggest there be another option to specify what contents of the internal
dir is allowed to be deleted. So:

    // if dirPath contains anything at all, returns false
    bool ok = QDir::removeInternalDir(dirPath, QDir::RemoveEmptyDir
/*default*/);

    // if there are any dirs in dirPath, returns false
    bool ok = QDir::removeInternalDir(dirPath, QDir::RemoveContainedFiles);

    // if there are any files in dirPath, returns false
    bool ok = QDir::removeInternalDir(dirPath, QDir::RemoveContainedDirs);

    // rm -rf
    bool ok = QDir::removeInternalDir(dirPath, QDir::RemoveContainedFiles |

QDir::RemoveContainedDirs |
                                                    QDir::RemoveRecursively
                                                    );

Unfortunately, I can't think of valid use-cases for delete-files-only and
delete-dirs-only calls.

roop.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20111118/d24dedc1/attachment.html>


More information about the Development mailing list