- (message "Unknown type %s; ignoring" type))))))
-
-(defun gnus-cloud-update-file (elem)
- (let ((file-name (plist-get elem :file-name))
- (date (plist-get elem :timestamp))
- (contents (plist-get elem :contents)))
- (unless (gnus-cloud-file-covered-p file-name)
- (message "%s isn't covered by the cloud; ignoring" file-name))
- (when (or (not (file-exists-p file-name))
- (and (file-exists-p file-name)
- (mm-with-unibyte-buffer
- (insert-file-contents-literally file-name)
- (not (equal (buffer-string) contents)))))
- (gnus-cloud-replace-file file-name date contents))))
+ (gnus-message 1 "Unknown type %s; ignoring" type))))))
+
+(defun gnus-cloud-update-newsrc-data (group elem &optional force-older)
+ "Update the newsrc data for GROUP from ELEM.
+Use old data if FORCE-OLDER is not nil."
+ (let* ((contents (plist-get elem :contents))
+ (date (or (plist-get elem :timestamp) "0"))
+ (now (gnus-cloud-timestamp (current-time)))
+ (newer (string-lessp date now))
+ (group-info (gnus-get-info group)))
+ (if (and contents
+ (stringp (nth 0 contents))
+ (integerp (nth 1 contents)))
+ (if group-info
+ (if (equal (format "%S" group-info)
+ (format "%S" contents))
+ (gnus-message 3 "Skipping cloud update of group %s, the info is the same" group)
+ (if (and newer (not force-older))
+ (gnus-message 3 "Skipping outdated cloud info for group %s, the info is from %s (now is %s)" group date now)
+ (when (or (not gnus-cloud-interactive)
+ (gnus-y-or-n-p
+ (format "%s has older different info in the cloud as of %s, update it here? "
+ group date))))
+ (gnus-message 2 "Installing cloud update of group %s" group)
+ (gnus-set-info group contents)
+ (gnus-group-update-group group)))
+ (gnus-error 1 "Sorry, group %s is not subscribed" group))
+ (gnus-error 1 "Sorry, could not update newsrc for group %s (invalid data %S)"
+ group elem))))
+
+(defun gnus-cloud-update-file (elem op)
+ "Apply Gnus Cloud data ELEM and operation OP to a file."
+ (let* ((file-name (plist-get elem :file-name))
+ (date (plist-get elem :timestamp))
+ (contents (plist-get elem :contents))
+ (exists (file-exists-p file-name)))
+ (if (gnus-cloud-file-covered-p file-name)
+ (cond
+ ((eq op :delete)
+ (if (and exists
+ ;; prompt only if the file exists already
+ (or (not gnus-cloud-interactive)
+ (gnus-y-or-n-p (format "%s has been deleted as of %s, delete it locally? "
+ file-name date))))
+ (rename-file file-name (car (find-backup-file-name file-name)))
+ (gnus-message 3 "%s was already deleted before the cloud got it" file-name)))
+ ((eq op :file)
+ (when (or (not exists)
+ (and exists
+ (mm-with-unibyte-buffer
+ (insert-file-contents-literally file-name)
+ (not (equal (buffer-string) contents)))
+ ;; prompt only if the file exists already
+ (or (not gnus-cloud-interactive)
+ (gnus-y-or-n-p (format "%s has updated contents as of %s, update it? "
+ file-name date)))))
+ (gnus-cloud-replace-file file-name date contents))))
+ (gnus-message 2 "%s isn't covered by the cloud; ignoring" file-name))))