Skip to content

File.OpenHandle does not respect FileOptions.DeleteOnClose on Unix #55132

Closed

Description

@stephentoub

Repro:

using System;
using System.IO;
using Microsoft.Win32.SafeHandles;

string path = "test.dat";
var h = File.OpenHandle("test.dat", FileMode.Create, FileAccess.ReadWrite, FileShare.None, FileOptions.DeleteOnClose);
Console.WriteLine(File.Exists(path));
h.Dispose();
Console.WriteLine(File.Exists(path));

This should print true then false, but on Unix it prints true then true.

Note this isn't a case of DeleteOnClose not working on Unix. It does, e.g. change the repro to use:

var h = File.Create("test.dat", 1, FileOptions.DeleteOnClose);

instead, and it'll correctly print out the expected results.

Rather, the code on Unix to handle emulating FileOptions.DeleteOnClose is part of FileStream.Dispose and should likely instead be a part of SafeFileHandle.

cc: @adamsitnik

Activity

  1. added this to the 6.0.0 milestone on Jul 3, 2021
  2. ghost added
    untriaged
    on Jul 3, 2021
  3. self-assigned this
    on Jul 4, 2021
  4. ghost added
    in-pr
    on Jul 4, 2021
  5. removed
    untriaged
    on Jul 5, 2021
  6. ghost removed
    in-pr
    on Jul 6, 2021
  7. ghost locked as resolved and limited conversation to collaborators on Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions