From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Adrian Robert" Newsgroups: gmane.emacs.devel Subject: Re: Large-file check in files.el Date: Tue, 1 Apr 2008 15:02:04 +0300 Message-ID: <55f7df060804010502j689f88c4k8888030298f3d065@mail.gmail.com> References: <55f7df060803312155wdfe27c0w5bbbaac1562285a4@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1207051382 30373 80.91.229.12 (1 Apr 2008 12:03:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 1 Apr 2008 12:03:02 +0000 (UTC) Cc: emacs- devel To: "Stefan Monnier" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Apr 01 14:03:34 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JgfCs-0000Zg-BA for ged-emacs-devel@m.gmane.org; Tue, 01 Apr 2008 14:03:14 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JgfCG-0008U8-84 for ged-emacs-devel@m.gmane.org; Tue, 01 Apr 2008 08:02:36 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JgfBq-00082c-Qu for emacs-devel@gnu.org; Tue, 01 Apr 2008 08:02:10 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JgfBo-00081T-0k for emacs-devel@gnu.org; Tue, 01 Apr 2008 08:02:10 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JgfBn-00081O-QJ for emacs-devel@gnu.org; Tue, 01 Apr 2008 08:02:07 -0400 Original-Received: from wr-out-0506.google.com ([64.233.184.229]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JgfBn-0006Kk-D3 for emacs-devel@gnu.org; Tue, 01 Apr 2008 08:02:07 -0400 Original-Received: by wr-out-0506.google.com with SMTP id 57so1381618wri.12 for ; Tue, 01 Apr 2008 05:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=plv+Lsw1BeVrN0Wm+s+WjQPUZRQAWZVqXbP8PP+efuY=; b=iXvUKP4sB4xf86+IfDTzCcBqzJcDPT+RAEupMFQ9i0JWEe4Td792P7ddfH4tYHh9l5KlagK/33xl8wVTE3yyna8WWg/NjXWjH3N+PGSrCMBUCY7zyMReftH0PN6HwyHHXDMmrLhsypSuLiruo/xMDXSM55JQMEDBcnjLJnLjErk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ocSXCQIT/RlC9WIe/V2HvVrzqA5Uj5Q1rxx2Ovy3QU31Fzw8T5EJHpvCKFLEkJIRYMho3yfcV6uIjkkDalCLZJxRfa80raq8YG0ohYVsDAWGXruEJ29JNvW50HPLKy3We0OEbEJ00J0mCALr/ylXEhgxF5ATS2mF31sqgUHLFwI= Original-Received: by 10.141.185.3 with SMTP id m3mr4221106rvp.40.1207051324766; Tue, 01 Apr 2008 05:02:04 -0700 (PDT) Original-Received: by 10.141.193.8 with HTTP; Tue, 1 Apr 2008 05:02:04 -0700 (PDT) In-Reply-To: Content-Disposition: inline X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:94109 Archived-At: On Tue, Apr 1, 2008 at 8:57 AM, Stefan Monnier wrote: > > In find-file-noselect, confirmation is required for filesize > > > large-file-warning-threshold, yet in insert-file-1, it is not. Is > > there a reason large files should be allowed to be inserted -- but not > > loaded by themselves -- without confirmation? If not, I propose the > > patch below. > > That makes sense. But please factor out the size-check code into its > own function which you can then call from both places. This will be > better than duplicating the code like your patch currently does. OK, here is a new version of the patch. ------------------ Index: files.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/files.el,v retrieving revision 1.966 diff -c -b -r1.966 files.el *** files.el 14 Mar 2008 17:14:09 -0000 1.966 --- files.el 1 Apr 2008 12:00:30 -0000 *************** *** 1507,1512 **** --- 1507,1523 ---- :version "22.1" :type '(choice integer (const :tag "Never request confirmation" nil))) + (defun should-abort-large-file (attributes opType &optional buf nowarn) + "Utility function: return t if file is larger than large-file-warning-threshold + and user declines loading it. If buf or nowarn are true, always return nil." + (if (and large-file-warning-threshold (nth 7 attributes) (not (or buf nowarn))) + (and (> (nth 7 attributes) large-file-warning-threshold) + (not (y-or-n-p + (format "File %s is large (%dMB), really %s? " + (file-name-nondirectory filename) + (/ (nth 7 attributes) 1048576) opType)))) + nil)) + (defun find-file-noselect (filename &optional nowarn rawfile wildcards) "Read file FILENAME into a buffer and return the buffer. If a buffer exists visiting FILENAME, return that one, but *************** *** 1558,1572 **** (if (or find-file-existing-other-name find-file-visit-truename) (setq buf other)))) ;; Check to see if the file looks uncommonly large. ! (when (and large-file-warning-threshold (nth 7 attributes) ! ;; Don't ask again if we already have the file or ! ;; if we're asked to be quiet. ! (not (or buf nowarn)) ! (> (nth 7 attributes) large-file-warning-threshold) ! (not (y-or-n-p ! (format "File %s is large (%dMB), really open? " ! (file-name-nondirectory filename) ! (/ (nth 7 attributes) 1048576))))) (error "Aborted")) (if buf ;; We are using an existing buffer. --- 1569,1575 ---- (if (or find-file-existing-other-name find-file-visit-truename) (setq buf other)))) ;; Check to see if the file looks uncommonly large. ! (when (should-abort-large-file attributes "open" buf nowarn) (error "Aborted")) (if buf ;; We are using an existing buffer. *************** *** 1796,1801 **** --- 1799,1807 ---- (if (file-directory-p filename) (signal 'file-error (list "Opening input file" "file is a directory" filename))) + ;; Check whether the file is uncommonly large (see find-file-noselect): + (when (should-abort-large-file (file-attributes filename) "insert") + (error "Aborted")) (let* ((buffer (find-buffer-visiting (abbreviate-file-name (file-truename filename)) #'buffer-modified-p)) (tem (funcall insert-func filename))) Diffs between working revision and workfile end here.