Skip to content

Zipped file remains locked after ZipFile().CreateFromDirectory #763

@agtalex

Description

@agtalex

Thanks for the amazing work on the Testably libraries.

I'm getting a lock error on a file that was zipped

System.IO.IOException
The process cannot access the file 'C:\ToBeZipped\file.txt' because it is being used by another process.
   at Testably.Abstractions.Testing.Storage.InMemoryContainer.RequestAccess(FileAccess access, FileShare share, Boolean deleteAccess, Boolean ignoreFileShare, Boolean ignoreMetadataErrors, Nullable`1 hResult)
   at Testably.Abstractions.Testing.Storage.InMemoryStorage.DeleteContainer(IStorageLocation location, FileSystemTypes expectedType, Boolean recursive)
   at Testably.Abstractions.Testing.Storage.InMemoryStorage.DeleteContainer(IStorageLocation location, FileSystemTypes expectedType, Boolean recursive)
   at Testably.Abstractions.Testing.FileSystem.DirectoryInfoMock.Delete(Boolean recursive)
   at Testably.Abstractions.Testing.FileSystem.DirectoryMock.Delete(String path, Boolean recursive)

You can repro with this test:

using System.IO.Abstractions;
using Testably.Abstractions;
using Testably.Abstractions.Testing;

namespace TestProject1;

public class UnitTest1
{
    [Fact]
    public void Test1()
    {
        IFileSystem fileSystem = new MockFileSystem();
        string directory = @"C:\ToBeZipped";
        string file = fileSystem.Path.Combine(directory, "file.txt");
        string archive = @"c:\zippedDirectory.zip";

        fileSystem.Directory.CreateDirectory(directory);
        fileSystem.File.WriteAllText(file, "Some content");

        fileSystem.ZipFile().CreateFromDirectory(directory, archive);
        fileSystem.Directory.Delete(directory, true);
    }
}

Problem doesn't occur with a RealFileSystem.

Thanks for looking into this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions