mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	Merge #5159 from justinmk/readfile-readonly-check
This commit is contained in:
		| @@ -493,23 +493,15 @@ readfile ( | |||||||
|     curbuf->b_flags &= ~(BF_NEW | BF_NEW_W); |     curbuf->b_flags &= ~(BF_NEW | BF_NEW_W); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /* |   // Check readonly. | ||||||
|    * Check readonly by trying to open the file for writing. |   file_readonly = false; | ||||||
|    * If this fails, we know that the file is readonly. |  | ||||||
|    */ |  | ||||||
|   file_readonly = FALSE; |  | ||||||
|   if (!read_buffer && !read_stdin) { |   if (!read_buffer && !read_stdin) { | ||||||
|     if (!newfile || readonlymode) { |     if (!newfile || readonlymode || !(perm & 0222) | ||||||
|       file_readonly = TRUE; |         || !os_file_is_writable((char *)fname)) { | ||||||
|     } else if ((fd = os_open((char *)fname, O_RDWR, 0)) < 0) { |       file_readonly = true; | ||||||
|       // opening in readwrite mode failed => file is readonly |  | ||||||
|       file_readonly = TRUE; |  | ||||||
|     } |     } | ||||||
|     if (file_readonly == TRUE) { |  | ||||||
|       // try to open readonly |  | ||||||
|     fd = os_open((char *)fname, O_RDONLY, 0); |     fd = os_open((char *)fname, O_RDONLY, 0); | ||||||
|   } |   } | ||||||
|   } |  | ||||||
|  |  | ||||||
|   if (fd < 0) {                     /* cannot open at all */ |   if (fd < 0) {                     /* cannot open at all */ | ||||||
|     msg_scroll = msg_save; |     msg_scroll = msg_save; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Justin M. Keyes
					Justin M. Keyes