# HG changeset patch # User Markus Mützel # Date 1666807607 -7200 # Wed Oct 26 20:06:47 2022 +0200 # Node ID 90d5a291dd064132d916e93d0d07cb8ffe0beaba # Parent 0c653041846038b8b70fa750e21743eb65608b16 unlink: Also remove files with their read-only flag set on Windows (bug #63265). * liboctave/wrappers/unistd-wrappers.c (octave_unlink_wrapper): _wunlink fails on Windows when trying to unlink files that have their read-only flag set. Try to un-set that flag before unlinking. diff -r 0c6530418460 -r 90d5a291dd06 liboctave/wrappers/unistd-wrappers.c --- a/liboctave/wrappers/unistd-wrappers.c Wed Oct 26 19:12:39 2022 +0200 +++ b/liboctave/wrappers/unistd-wrappers.c Wed Oct 26 20:06:47 2022 +0200 @@ -380,8 +380,16 @@ { #if defined (OCTAVE_USE_WINDOWS_API) wchar_t *wnm = u8_to_wchar (nm); + + // _wunlink fails on files with the read-only flag set. Try to un-set it. + DWORD file_attributes = GetFileAttributesW (wnm); + if (file_attributes != INVALID_FILE_ATTRIBUTES + && file_attributes & FILE_ATTRIBUTE_READONLY) + SetFileAttributesW (wnm, file_attributes & ~FILE_ATTRIBUTE_READONLY); + int status = _wunlink (wnm); free ((void *) wnm); + return status; #else return unlink (nm);