RFC: boolean to disable autocreate in locateLocal

Luis Pedro Coelho luis_pedro at netcabo.pt
Sun May 18 16:48:46 BST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Le Dimanche 18 Mai 2003 17:23, Waldo Bastian a écrit :
> On Sunday 18 May 2003 14:39, Tobias Koenig wrote:
> > Could we add a boolean parameter to locateLocal() to avoid
> > autocreation of the file/directory?
>
> Yes, I will do so. The docu of locateLocal said that it always creates the
> dirs, unfortunately the implementation didn't. I fixed that for 3.2 but it
> is probably better to add a flag for it instead.
>
> It should never create a file btw.

I can understand that creating the file is not good, but I don't see how the 
code does, that. Here is the code to locateLocal:

QString locateLocal( const char *type,
                    const QString& filename,
		const KInstance* inst /* = KGlobal::instance() */)
{
    // try to find slashes. If there are some, we have to
    // create the subdir first
    int slash = filename.findRev('/')+1;
    if (!slash) // only one filename
       return inst->dirs()->saveLocation(type, QString::null, true) 
			+ filename;

    // split path from filename
    QString dir = filename.left(slash);
    QString file = filename.mid(slash);
    return inst->dirs()->saveLocation(type, dir, true) + file;
}

I don't see how the file gets created. It does create the directory (the true 
parameter in the saveLocation call). 
Or am I misreading this?

Tobias, did you oversimplify your example? It is valid if you write (note that 
filename ends in '/'):

if (QFile::exists(locateLocal("data","mydir/")) // <- always true
  do_something() ; 
else { / * UNREACHABLE CODE */ ; }

Regards,
- -- 
Luis Pedro Coelho

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+x6teGpBAvyRwXdgRAonLAKDMwDrbgf4nNmkSSHYJCdwO3zt91wCglqG0
QE5esRa003yTSPz7blFWzm0=
=IuOh
-----END PGP SIGNATURE-----




More information about the kde-core-devel mailing list