unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefan@marxist.se>
To: 41000@debbugs.gnu.org
Cc: Compro Prasad <comproprasad@gmail.com>,
	Lars Ingebrigtsen <larsi@gnus.org>
Subject: bug#41000: Fwd: bug#41000: 28.0.50; Package file(.el) is 0 bytes after downloading
Date: Tue, 24 Aug 2021 16:29:18 +0200	[thread overview]
Message-ID: <CADwFkmkL7YUB7QOyhN6fgrq+vbifoxCVafHcULVZZ3oZAwrguw@mail.gmail.com> (raw)
In-Reply-To: <CAF5vbPmvMt9C21L-gBbH1fuci32RYX35ZQZM5xY5WjEDDSZ57A@mail.gmail.com>

It seems like the below was sent to me in private, without using
"Reply to all" so it never reached the bug tracker.  I am therefore
forwarding the full message here.

---------- Forwarded message ---------
Från: Compro Prasad <comproprasad@gmail.com>
Date: mån 11 maj 2020 kl 09:00
Subject: Re: bug#41000: 28.0.50; Package file(.el) is 0 bytes after downloading
To: Stefan Kangas <stefan@marxist.se>


On Sat, May 9, 2020 at 12:04 AM Stefan Kangas <stefan@marxist.se> wrote:
>
> Compro Prasad <comproprasad@gmail.com> writes:
>
> > There isn't a valid way to reproduce this issue. It mostly works fine. But
> > this has occured with me in the past too but thought it was already
> > reported.
>
> Could you tell us anything else regarding the circumstances when this
> happens, or is it completely random?
Its completely random and mostly rare. Network might be an issue. But am
not sure.
> How frequent is it?
Its rare.
> Also, could you please try using "emacs -Q" while installing and/or
> upgrading packages for a while to see if you can reproduce this issue
> there?
There isn't a valid way to reproduce this. It happens at random, maybe due
to network issues.
> > To be very specific I have mostly found the .el file having 0 bytes size.
> > Other files mostly had sizes greater than 0 bytes.
>
> Which other files are you referring to?  Do you mean other files inside
> a multi file package?
I am referring to the .el files of the package that I install using
package-install.

I have used an advice after package-install and also an after-init-hook
function that checks for any empty file which fixes this thing for now. Its
given below.

(defun compro/get-empty-pkgs ()
  "Get 0 bytes .el packages."
  (let ((default-directory package-user-dir))
    (seq-reduce
     (lambda (value-list file)
       (if (= (file-attribute-size (file-attributes file)) 0)
           (cons file value-list)
         value-list))
     (seq-filter
      (apply-partially #'s-suffix-p ".el")
      (seq-reduce
       (lambda (value-list file)
         (if (and
              (not (s-prefix-p "." file))
              (file-accessible-directory-p file))
             (append
              (seq-map
               (apply-partially #'concat file "/")
               (directory-files file))
              value-list)
           value-list))
       (directory-files "")
       '()))
     '())))

(defun compro/redownload-empty-pkgs ()
  "Redownload empty packages."
  (interactive)
  (let* ((pkgs (compro/get-empty-pkgs))
         (default-directory package-user-dir)
         (choice-list (list
                       (cons (intern "Delete and re-download all") 1)
                       (cons (intern "Manually select for re-downloading") 2)
                       (cons (intern "Fix everything manually") 3)))
         (choice (if pkgs
                     (alist-get
                      (intern
                       (completing-read
                        (concat
                         "Some files were not properly downloaded namely "
                         (s-join ", " pkgs)
                         ". What action do you want to take?  ")
                        choice-list))
                      choice-list)
                   3)))
    (if (= choice 3)
        (when (null pkgs)
          (message "No empty packages were found"))
      (package-refresh-contents)
      (seq-each
       (lambda (file)
         (let* ((values (s-split "/" file))
                (dir-name (car values))
                (pkg-values (s-split "-" dir-name))
                (pkg-name (s-join "-" (butlast pkg-values 1)))
                (each-choice
                 (if (= choice 1)
                     t
                   (yes-or-no-p
                    (concat "Delete and re-download " dir-name "? ")))))
           (when each-choice
             (delete-directory dir-name t)
             (ignore-errors
               (package-reinstall (intern pkg-name))))))
       pkgs))))
(add-hook 'after-init-hook 'compro/redownload-empty-packages)

(defun re-download (pkg &optional arg)
  "Advice for package-install."
  (let* ((pkg-name (symbol-name (if (package-desc-p pkg)
                                    (package-desc-name pkg)
                                  pkg)))
         (file-name (car
                     (sort
                      (seq-filter
                       (apply-partially #'s-prefix-p pkg-name)
                       (compro/get-empty-pkgs))
                      #'string-greaterp)))
         (dir (when file-name (car (s-split "/" file-name)))))
    (when dir
      (delete-directory dir)
      (ignore-errors (package-reinstall pkg)))))
(advice-add 'package-install :after 're-download)


My elisp skills aren't great but the above fixes my issue for now.
Would be nice to have something concrete to handle this issue.

Regards,
Compro Prasad





      parent reply	other threads:[~2021-08-24 14:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-01 14:39 bug#41000: 28.0.50; Package file(.el) is 0 bytes after downloading comproprasad
2020-05-03 20:15 ` Stefan Kangas
2020-05-03 20:56   ` Noam Postavsky
2020-05-03 20:59     ` Stefan Kangas
2021-08-10 15:57   ` Lars Ingebrigtsen
2021-08-10 17:06     ` Compro Prasad
2021-08-11 11:07       ` Lars Ingebrigtsen
2021-08-11 11:38         ` Compro Prasad
     [not found]   ` <CAF5vbPmCoDV0TbytBL1xz4wz_BLiBmiA3MCTLEJHZa0kkKqj1w@mail.gmail.com>
     [not found]     ` <CADwFkm=pXfZzM_9Z71trmt3OfTNeTaY-YXC_g=4iFHYpSrw+fg@mail.gmail.com>
     [not found]       ` <CAF5vbPmvMt9C21L-gBbH1fuci32RYX35ZQZM5xY5WjEDDSZ57A@mail.gmail.com>
2021-08-24 14:29         ` Stefan Kangas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADwFkmkL7YUB7QOyhN6fgrq+vbifoxCVafHcULVZZ3oZAwrguw@mail.gmail.com \
    --to=stefan@marxist.se \
    --cc=41000@debbugs.gnu.org \
    --cc=comproprasad@gmail.com \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).