Hi,

I have a class which unzips an archive into a temporary directory below the 
system temp folder. I want to delete this temporary directory in the class's 
destructor, but when I call rmdir there, I get an

core.exception.InvalidMemoryOperationError@(0)

The effect is not limited to this special case. Whenever I call rmdir in the 
destructor, no matter for which directory, I get the same error.

Environment: DMD v2.066.1 (from D-Apt) on Ubuntu 14.10 (32 and 64 bit).

Sample code:

// -------------------------------------------
module main;

import std.stdio;
import std.file;
import std.path;

class RmdirTest
{
        private string sTempDir;

        this(string sInstanceName)
        {
                writeln("Constructor called");
                sTempDir=tempDir() ~ dirSeparator ~ sInstanceName;
                mkdir (sTempDir);
        }

        ~this()
        {
                writeln("Destructor called");

                if (sTempDir !is null)
                {
                        rmdir(sTempDir);
                }
        }
}

void main(string[] args)
{
        RmdirTest rmDirTest=new RmdirTest("123");
}
// -------------------------------------------

Console output is:

Constructor called
Destructor called
core.exception.InvalidMemoryOperationError@(0)

The directory "/tmp/123" is created, but not deleted.

When I change the line "(sTempDir !is null)" to "((sTempDir !is null) && 
(exists(sTempDir)) && (isDir(sTempDir)))", the exception is thrown already on 
this line, so obviously  the problem also applies to other file functions like 
exists and isDir.

Is there any solution for this?

Thanks and best regards,
Timo

Reply via email to