Loading ...
Sorry, an error occurred while loading the content.

Re: Patch 6.1.148 (extra)

Expand Messages
  • Glenn Maynard
    ... CreateFile isn t good with directories. How about something like this: if(mch_isdir(n)) { int ret = 0; if(p & R_OK) { char TempDir[_MAX_PATH+16] = ;
    Message 1 of 6 , Aug 5, 2002
    • 0 Attachment
      On Mon, Aug 05, 2002 at 01:55:36PM +0200, Bram Moolenaar wrote:
      > > I'm using gvim on W2K with NTFS.
      > > After applied this patch, filewritable() never return 2 for a directory.
      > > It will be reproduced by:
      > > :echo filewritable($VIM)
      > > Please check it.
      >
      > Thanks for reporting this. Mike, can this be fixed?

      CreateFile isn't good with directories. How about something like this:

      if(mch_isdir(n)) {
      int ret = 0;
      if(p & R_OK) {
      char TempDir[_MAX_PATH+16] = "";
      WIN32_FIND_DATA d;

      strncpy(TempDir, n, _MAX_PATH);
      if(!strchr("/\\", TempDir[strlen(TempDir)-1]))
      strncat(TempDir, "\\", _MAX_PATH);
      strncat(TempDir, "*", _MAX_PATH);

      if(FindFirstFile(n, &d) == INVALID_HANDLE_VALUE)
      ret = -1;
      }

      if(ret == 0 && (p & W_OK)) {
      char TempFile[_MAX_PATH+1];
      if (GetTempFileName(n, "VIM", 0, TempFile))
      mch_remove((char_u *) TempFile);
      else
      ret = -1;
      }
      return ret;
      }

      (No patch, because my vim_access() also has mbyte support added.)

      --
      Glenn Maynard
    • Mike Williams
      ... Yup - hadn t realised it was also used for filewritable() on directories. The whole area is a mess due to ACLs (not working on Samba) and read-only
      Message 2 of 6 , Aug 6, 2002
      • 0 Attachment
        On 5 Aug 2002 at 13:04, Glenn Maynard wrote:

        > On Mon, Aug 05, 2002 at 01:55:36PM +0200, Bram Moolenaar wrote:
        > > > I'm using gvim on W2K with NTFS.
        > > > After applied this patch, filewritable() never return 2 for a directory.
        > > > It will be reproduced by:
        > > > :echo filewritable($VIM)
        > > > Please check it.
        > >
        > > Thanks for reporting this. Mike, can this be fixed?
        >
        > CreateFile isn't good with directories.

        Yup - hadn't realised it was also used for filewritable() on
        directories. The whole area is a mess due to ACLs (not working on
        Samba) and read-only shares.

        > How about something like this:
        >
        > if(mch_isdir(n)) {
        > int ret = 0;
        > if(p & R_OK) {
        > char TempDir[_MAX_PATH+16] = "";
        > WIN32_FIND_DATA d;
        >
        > strncpy(TempDir, n, _MAX_PATH);
        > if(!strchr("/\\", TempDir[strlen(TempDir)-1]))
        > strncat(TempDir, "\\", _MAX_PATH);
        > strncat(TempDir, "*", _MAX_PATH);
        >
        > if(FindFirstFile(n, &d) == INVALID_HANDLE_VALUE)
        > ret = -1;
        > }
        >
        > if(ret == 0 && (p & W_OK)) {
        > char TempFile[_MAX_PATH+1];
        > if (GetTempFileName(n, "VIM", 0, TempFile))
        > mch_remove((char_u *) TempFile);
        > else
        > ret = -1;
        > }
        > return ret;
        > }

        Looks a goer. Need to have a play with it with some ACL settings -
        can't remember if you can create a file in a directory but not delete
        it which could be a pain.

        Mike
        --
        The only thing blue movies leave to the imagination is the plot!
      • Mike Williams
        Hi, I have now had a chance to investigate this a bit more. The approach suggested by Glenn works apart from one set of ACL settings where the directory s ACL
        Message 3 of 6 , Aug 13, 2002
        • 0 Attachment
          Hi,

          I have now had a chance to investigate this a bit more. The approach
          suggested by Glenn works apart from one set of ACL settings where the
          directory's ACL allows the user to create files but is denied
          deleting them. The check for a writable directory will leave empty
          files lying around since mch_remove() fails - which may not be nice.
          Of course, the solution would be add a proper ACL check - hang on,
          isn't that where we started with all this? ;-)

          I'll have to root around for the previous ACL checking code I
          submitted with the Samba checks in it, and and an ACL check before
          attempting to create the temporary file (still need to do this since
          this catches read-only shares). Later this week hopefully.

          Ah, found a bug! Set the read-only flag on a directory and do :echo
          filewritable(...) on it - you get a value of 0 but you can in fact
          write files to the directory. The read-only attribute just adds a
          level or protection against accidental renaming or deletion. This is
          under W2K but I assume other Win/NT versions are the same. The
          simplest fix is to modify mch_writable() to always return true for a
          directory.

          One final thing (well done if you are still reading this) - why
          doesn't filereadable() work for directories like filewritable does?

          TTFN

          On 5 Aug 2002 at 13:04, Glenn Maynard wrote:

          > On Mon, Aug 05, 2002 at 01:55:36PM +0200, Bram Moolenaar wrote:
          > > > I'm using gvim on W2K with NTFS.
          > > > After applied this patch, filewritable() never return 2 for a directory.
          > > > It will be reproduced by:
          > > > :echo filewritable($VIM)
          > > > Please check it.
          > >
          > > Thanks for reporting this. Mike, can this be fixed?
          >
          > CreateFile isn't good with directories. How about something like this:
          >
          > if(mch_isdir(n)) {
          > int ret = 0;
          > if(p & R_OK) {
          > char TempDir[_MAX_PATH+16] = "";
          > WIN32_FIND_DATA d;
          >
          > strncpy(TempDir, n, _MAX_PATH);
          > if(!strchr("/\\", TempDir[strlen(TempDir)-1]))
          > strncat(TempDir, "\\", _MAX_PATH);
          > strncat(TempDir, "*", _MAX_PATH);
          >
          > if(FindFirstFile(n, &d) == INVALID_HANDLE_VALUE)
          > ret = -1;
          > }
          >
          > if(ret == 0 && (p & W_OK)) {
          > char TempFile[_MAX_PATH+1];
          > if (GetTempFileName(n, "VIM", 0, TempFile))
          > mch_remove((char_u *) TempFile);
          > else
          > ret = -1;
          > }
          > return ret;
          > }
          >
          > (No patch, because my vim_access() also has mbyte support added.)
          >
          > --
          > Glenn Maynard

          Mike
          --
          I've got to start listening to those quiet, nagging doubts.
        Your message has been successfully submitted and would be delivered to recipients shortly.