OSDN Git Service

Fix MinGW-Bug #3295526 (reported by Charles Wilson).
[mingw/mingw-get.git] / src / pkgunst.cpp
index 03eb5a2..599eb8c 100644 (file)
@@ -263,6 +263,14 @@ int pkg_rmdir( const char *sysroot, const char *pathname )
   return retval;
 }
 
+/* We want the following "unlink" function to emulate "rm -f"
+ * semantics; thus we need to ensure that each file we attempt
+ * to unlink is writeable.  To do this, we call "chmod()" prior
+ * to "unlink()"; we need sys/stat.h for the S_IWRITE mode we
+ * are required to set.
+ */
+#include <sys/stat.h>
+
 static __inline__ __attribute__((__always_inline__))
 int pkg_unlink( const char *sysroot, const char *pathname )
 {
@@ -282,6 +290,7 @@ int pkg_unlink( const char *sysroot, const char *pathname )
        dmh_printf( "  %s: unlink file\n", filepath )
       );
 
+    chmod( filepath, S_IWRITE );
     if( ((retval = unlink( filepath )) != 0) && (errno != ENOENT) )
       dmh_notify( DMH_WARNING, "%s:unlink failed; %s\n", filepath, strerror( errno ) );
   }