Skip to content

Commit

Permalink
Improved temp file handling. Issue fo-dicom#69
Browse files Browse the repository at this point in the history
  • Loading branch information
anders9ustafsson committed Sep 2, 2015
1 parent 34fba79 commit 57204f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 10 additions & 0 deletions DICOM [Unit Tests]/IO/DesktopFileReferenceTest.cs
Expand Up @@ -21,6 +21,16 @@ public void Constructor_TempFile_TempFileAttributeSet()
Assert.True((File.GetAttributes(path) & FileAttributes.Temporary) == FileAttributes.Temporary);
}

[Fact]
public void Constructor_RegularFile_TempFileAttributeNotSet()
{
var path = @".\Test Data\tmp.tmp";
File.Create(path).Dispose();

var file = new DesktopFileReference(path, false);
Assert.False((File.GetAttributes(path) & FileAttributes.Temporary) == FileAttributes.Temporary);
}

#endregion
}
}
10 changes: 2 additions & 8 deletions DICOM/IO/DesktopFileReference.cs
Expand Up @@ -30,13 +30,7 @@ public DesktopFileReference(string fileName, bool isTempFile = false)
{
if (this.IsTempFile)
{
try
{
this.Delete();
}
catch
{
}
TemporaryFileRemover.Delete(this.Name);
}
}

Expand Down Expand Up @@ -66,7 +60,7 @@ public bool IsTempFile
}
set
{
if (value)
if (value && this.Exists)
{
try
{
Expand Down

0 comments on commit 57204f2

Please sign in to comment.