Skip to content

Commit edb70e5

Browse files
committed
Add PhDeleteFile
1 parent f0ad15f commit edb70e5

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

phlib/include/phnative.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,13 @@ PhSetFileSize(
491491
_In_ PLARGE_INTEGER Size
492492
);
493493

494+
PHLIBAPI
495+
NTSTATUS
496+
NTAPI
497+
PhDeleteFile(
498+
_In_ HANDLE FileHandle
499+
);
500+
494501
PHLIBAPI
495502
NTSTATUS
496503
NTAPI

phlib/native.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,6 +2528,24 @@ NTSTATUS PhSetFileSize(
25282528
);
25292529
}
25302530

2531+
NTSTATUS PhDeleteFile(
2532+
_In_ HANDLE FileHandle
2533+
)
2534+
{
2535+
FILE_DISPOSITION_INFORMATION dispositionInfo;
2536+
IO_STATUS_BLOCK isb;
2537+
2538+
dispositionInfo.DeleteFile = TRUE;
2539+
2540+
return NtSetInformationFile(
2541+
FileHandle,
2542+
&isb,
2543+
&dispositionInfo,
2544+
sizeof(FILE_DISPOSITION_INFORMATION),
2545+
FileDispositionInformation
2546+
);
2547+
}
2548+
25312549
NTSTATUS PhGetFileHandleName(
25322550
_In_ HANDLE FileHandle,
25332551
_Out_ PPH_STRING *FileName
@@ -7315,20 +7333,10 @@ static BOOLEAN PhpDeleteDirectoryCallback(
73157333
FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT
73167334
)))
73177335
{
7318-
IO_STATUS_BLOCK isb;
7319-
FILE_DISPOSITION_INFORMATION fileInfo;
7320-
73217336
PhEnumDirectoryFile(directoryHandle, NULL, PhpDeleteDirectoryCallback, fullName);
73227337

73237338
// Delete the directory.
7324-
fileInfo.DeleteFile = TRUE;
7325-
NtSetInformationFile(
7326-
directoryHandle,
7327-
&isb,
7328-
&fileInfo,
7329-
sizeof(FILE_DISPOSITION_INFORMATION),
7330-
FileDispositionInformation
7331-
);
7339+
PhDeleteFile(directoryHandle);
73327340

73337341
NtClose(directoryHandle);
73347342
}
@@ -7401,9 +7409,6 @@ NTSTATUS PhDeleteDirectory(
74017409

74027410
if (NT_SUCCESS(status))
74037411
{
7404-
IO_STATUS_BLOCK isb;
7405-
FILE_DISPOSITION_INFORMATION fileInfo;
7406-
74077412
// Remove any files or folders inside the directory.
74087413
status = PhEnumDirectoryFile(
74097414
directoryHandle,
@@ -7413,14 +7418,7 @@ NTSTATUS PhDeleteDirectory(
74137418
);
74147419

74157420
// Remove the directory.
7416-
fileInfo.DeleteFile = TRUE;
7417-
status = NtSetInformationFile(
7418-
directoryHandle,
7419-
&isb,
7420-
&fileInfo,
7421-
sizeof(FILE_DISPOSITION_INFORMATION),
7422-
FileDispositionInformation
7423-
);
7421+
PhDeleteFile(directoryHandle);
74247422

74257423
NtClose(directoryHandle);
74267424
}

0 commit comments

Comments
 (0)