Skip to content

Commit

Permalink
Fixes the remaining failure to delete cab problem, thus fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
activescott committed Dec 6, 2013
1 parent 563e3c0 commit c297284
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/LessMsi/Msi/Wixtracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ public static void ExtractFiles(FileInfo msi, DirectoryInfo outputDir, MsiFile[]
}
finally
{ //cleanup the decompressors allocated in MergeCabs
foreach (MSCabinet decomp in cabDecompressors)
foreach (var decomp in cabDecompressors)
{
decomp.Close(false);
File.Delete(decomp.LocalFilePath);
DeleteFileForcefully(decomp.LocalFilePath);
}
}
}
Expand All @@ -354,6 +354,20 @@ public static void ExtractFiles(FileInfo msi, DirectoryInfo outputDir, MsiFile[]
}

/// <summary>
/// Deletes a file even if it is readonly.
/// </summary>
private static void DeleteFileForcefully(string localFilePath)
{
// In github issue #4 found that the cab files in the Win7SDK have the readonly attribute set and File.Delete fails to delete them. Explicitly unsetting that bit before deleting works okay...
var fileAttributes = File.GetAttributes(localFilePath);
if ((fileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
File.SetAttributes(localFilePath, (fileAttributes & ~FileAttributes.ReadOnly));
}
File.Delete(localFilePath);
}

/// <summary>
/// Allocates a decompressor for each cab and merges any cabs that need merged.
/// </summary>
/// <param name="cabinets"></param>
Expand Down

0 comments on commit c297284

Please sign in to comment.