To: vim-dev@vim.org Subject: Patch 6.1.202 (extra) Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.202 (extra)(depends on 6.1.148) Problem: Win32: filewritable() doesn't work properly on directories. Solution: fix filewritable(). (Mike Williams) Files: src/os_win32.c *** ../vim61.201/src/os_win32.c Sun Aug 4 22:13:27 2002 --- src/os_win32.c Mon Sep 30 21:25:16 2002 *************** *** 2323,2335 **** /* * Return TRUE if file or directory "name" is writable (not readonly). */ int mch_writable(char_u *name) { int perm = mch_getperm(name); ! return (perm != -1 && !(perm & FILE_ATTRIBUTE_READONLY)); } #if defined(FEAT_EVAL) || defined(PROTO) --- 2323,2338 ---- /* * Return TRUE if file or directory "name" is writable (not readonly). + * Strange semantics of Win32: a readonly directory is writable, but you can't + * delete a file. Let's say this means it is writable. */ int mch_writable(char_u *name) { int perm = mch_getperm(name); ! return (perm != -1 && (!(perm & FILE_ATTRIBUTE_READONLY) ! || (perm & FILE_ATTRIBUTE_DIRECTORY))); } #if defined(FEAT_EVAL) || defined(PROTO) *************** *** 4021,4035 **** HANDLE hFile; DWORD am; ! /* Trying to open the file for the required access does ACL, read-only ! * network share, and file attribute checks. ! */ ! am = ((p & W_OK) ? GENERIC_WRITE : 0) ! | ((p & R_OK) ? GENERIC_READ : 0); ! hFile = CreateFile(n, am, 0, NULL, OPEN_EXISTING, 0, NULL); ! if (hFile == INVALID_HANDLE_VALUE) ! return -1; ! CloseHandle(hFile); return 0; } --- 4032,4086 ---- HANDLE hFile; DWORD am; ! if (mch_isdir(n)) ! { ! char TempName[_MAX_PATH + 16] = ""; ! ! if (p & R_OK) ! { ! /* Read check is performed by seeing if we can do a find file on ! * the directory for any file ! */ ! char *pch; ! WIN32_FIND_DATA d; ! ! STRNCPY(TempName, n, _MAX_PATH); ! pch = TempName + STRLEN(TempName) - 1; ! if (*pch != '\\' && *pch != '/') ! *pch++ = '\\'; ! *pch++ = '*'; ! *pch = NUL; ! ! hFile = FindFirstFile(TempName, &d); ! if (hFile == INVALID_HANDLE_VALUE) ! return -1; ! (void)FindClose(hFile); ! } ! ! if (p & W_OK) ! { ! /* Trying to create a temporary file in the directory should catch ! * directories on read-only network shares. However, in ! * directories whose ACL allows writes but denies deletes will end ! * up keeping the temporary file :-( ! */ ! if (!GetTempFileName(n, "VIM", 0, TempName)) ! return -1; ! mch_remove((char_u *)TempName); ! } ! } ! else ! { ! /* Trying to open the file for the required access does ACL, read-only ! * network share, and file attribute checks. ! */ ! am = ((p & W_OK) ? GENERIC_WRITE : 0) ! | ((p & R_OK) ? GENERIC_READ : 0); ! hFile = CreateFile(n, am, 0, NULL, OPEN_EXISTING, 0, NULL); ! if (hFile == INVALID_HANDLE_VALUE) ! return -1; ! CloseHandle(hFile); ! } return 0; } *** ../vim61.201/src/version.c Mon Sep 30 19:35:18 2002 --- src/version.c Mon Sep 30 21:27:54 2002 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 202, /**/ -- From "know your smileys": (:-# Said something he shouldn't have /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ /// Creator of Vim - Vi IMproved -- http://www.vim.org \\\ \\\ Project leader for A-A-P -- http://www.a-a-p.org /// \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///