Jump to content
Sign in to follow this  
Exit

Filedelete() returns wrong @error on failure with ADS streams

Recommended Posts

Exit

When using Filedelete() function on ADS files, Filedelete fails (Return=0), but @error is set to 0 (no error) and the ADS stream is not deleted.

Here a reproducer:

_Try("~temp.txt:ADS")
_Try("~temp.txt")

Func _Try($sFilename)
    FileWriteLine($sFilename, "This is a Test")
    MsgBox(262144, $sFilename, "Filename: " & $sFilename & @LF & @LF & "File before FileDelete():" & @LF & FileRead($sFilename))
    $rc = FileDelete($sFilename)
    MsgBox(262144, $sFilename, "If $rc is zero (no Success), @error should be NOT zero. (in my opinion)" & @LF & @LF & _
        "Filename: " & $sFilename & @LF & @LF & "Filedelete() return values      $rc: " & $rc & "   @error: " & @error & @LF & @LF & _
        @LF & "File after FileDelete():" & @LF & FileRead($sFilename), 0)
EndFunc   ;==>_Try

Autoit should set @error to 1 (nonzero)

Is it a bug or a feature ?

ADS = Alternate Data Stream (Google is your friend :thumbsup: )


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
KaFu
Exit

Yes, it is a bug in Autoit.

1. ADS files will never be deleted.

2. FileDelete() always sets @error to 0. Even on failure.

(ok, helpfile says nothing about @error)

I wrote _FileDelete() function based on Yashied's _WinAPI_DeleteFile()

and a reproducer:

_Try("~temp.txt:ADS")
_Try("~temp.txt")

Func _Try($sFilename)
    FileWriteLine($sFilename, "This is a Test")
    $Return = FileDelete($sFilename)
    $Error = @error
    ConsoleWrite(@lf&"Filename: " & $sFilename & @LF  & "Filedelete() $Return: " & $Return & "   @error: " & @error & @LF)
    If $Return+$Error= 0 Then ConsoleWrite("*** Bug *** ==> If $Return=0 (no Success), @error should be 1 " &  @LF )
    $Return = _FileDelete($sFilename)
    $Error = @error
    ConsoleWrite("_Filedelete() $Return: " & $Return & "   @error: " & @error & @LF& @LF)
EndFunc   ;==>_Try

Func _FileDelete($sFile)
    $sFile = DllCall('kernel32.dll', 'int', 'DeleteFileW', 'wstr', $sFile)
    Return SetError(Not $sFile[0], 0, $sFile[0])
EndFunc   ;==>_FileDelete

Here the console output:

Filename: ~temp.txt:ADS
Filedelete() $Return: 0   @error: 0
*** Bug *** ==> If $Return=0 (no Success), @error should be 1 
_Filedelete() $Return: 1   @error: 0

Filename: ~temp.txt
Filedelete() $Return: 1   @error: 0
_Filedelete() $Return: 0   @error: 1

The last _FileDelete fails since previous FileDelete() did the job already.

I modified TRAC #2221 Feature Request

and added TRAC #2321 Feature Request


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×