Closed Bug 553492 Opened 14 years ago Closed 14 years ago

Add Addon.size to expose the addon's size on disk

Categories

(Toolkit :: Add-ons Manager, defect)

defect
Not set
normal

Tracking

()

VERIFIED FIXED
mozilla2.0b2
Tracking Status
blocking2.0 --- beta2+

People

(Reporter: Unfocused, Assigned: mossop)

References

Details

(Keywords: APIchange, Whiteboard: [rewrite][schemachange])

Attachments

(1 file)

Add Addon.size to expose the addon's size on disk. This should be in bytes, or -1 for unknown.
Blocks: 561261
Note that bug 550048 now displays the 'size' and even can sort on it, but the actual value seems to be a random value (because 'Addon.size' is not available).
So, this has become a more visible issue.
Ben, the place to start looking to add this value to the backend API is here: http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/extensions/XPIProvider.jsm#4657

This is the wrapper that code outside the API sees and uses so you just need to add a size getter to it. In there aAddon._sourceBundle will be either an xpi file, in which case the size is obviously just the size of the file or a directory in which case you'll need to recurse through it adding up the full size. Because this might take time it is going to be sensible to cache the size the first time you calculate it and just return that directly for subsequent calls.
Assignee: nobody → bparr
Or calculate it after installation/update of an addon, and store that somewhere.
Assignee: bparr → dtownsend
blocking2.0: --- → beta2+
Whiteboard: [rewrite] → [rewrite][schemachange]
Bug 558834 is going to do a DB schema update to add this property.
Depends on: 558834
Whiteboard: [rewrite][schemachange] → [rewrite][schemachange][apichange]
Attached patch patch rev 1Splinter Review
This exposes the size property on add-on objects and adds implementations for plugins too. Also added support to the AddonRepository API to expose the size of the download in the same manner.
Attachment #454622 - Flags: review?(robert.bugzilla)
Keywords: APIchange
Whiteboard: [rewrite][schemachange][apichange] → [rewrite][schemachange]
Version: unspecified → Trunk
Comment on attachment 454622 [details] [diff] [review]
patch rev 1

>diff --git a/toolkit/mozapps/extensions/AddonRepository.jsm b/toolkit/mozapps/extensions/AddonRepository.jsm
>--- a/toolkit/mozapps/extensions/AddonRepository.jsm
>+++ b/toolkit/mozapps/extensions/AddonRepository.jsm
>@@ -139,16 +139,22 @@ AddonSearchResult.prototype = {
>   appDisabled: false,
> 
>   /**
>    * True if the user wants this add-on to be disabled
>    */
>   userDisabled: false,
> 
>   /**
>+   * The size of the add-ons files in bytes. For add-ons that have not yet been
>+   * downloaded this may be an estimated value.
nit: s/add-ons files/add-on's files/ and s/For add-ons that have not/For an add-on that has not/

>+   */
>+  size: null,
>+
>+  /**
>    * Indicates what scope the add-on is installed in, per profile, user,
>    * system or application
>    */
>   scope: AddonManager.SCOPE_PROFILE,
> 
>   /**
>    * True if the add-on is currently functional
>    */
>diff --git a/toolkit/mozapps/extensions/PluginProvider.jsm b/toolkit/mozapps/extensions/PluginProvider.jsm
>--- a/toolkit/mozapps/extensions/PluginProvider.jsm
>+++ b/toolkit/mozapps/extensions/PluginProvider.jsm
>@@ -200,16 +200,42 @@ function PluginWrapper(aId, aName, aDesc
>   });
> 
>   this.__defineGetter__("blocklistState", function() {
>     let bs = Cc["@mozilla.org/extensions/blocklist;1"].
>              getService(Ci.nsIBlocklistService);
>     return bs.getPluginBlocklistState(aTags[0]);
>   });
> 
>+  this.__defineGetter__("size", function() {
>+    function getFileSize(aFile) {
>+      if (aFile.isSymlink())
>+        return 0;
>+
>+      if (!aFile.isDirectory())
>+        return aFile.fileSize;
>+
>+      let size = 0;
>+      let entries = aFile.directoryEntries.QueryInterface(Ci.nsIDirectoryEnumerator);
>+      let entry;
>+      while (entry = entries.nextFile)
>+        size += getFileSize(entry);
>+      entries.close();
>+      return size;
>+    }
>+
>+    let size = 0;
>+    let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
>+    aTags.forEach(function(aTag) {
>+      file.initWithPath(aTag.fullpath);
>+      size += getFileSize(file);
>+    });
>+    return size;
>+  });
Seems like you could fairly easily check if the original file path is a symlink for the Linux case and get the size of the file while protecting against a symlink on Mac OS X pointing back to the original package.

I expected to see changes to XPIProvider.jsm in this patch... what's up with that?
Attachment #454622 - Flags: review?(robert.bugzilla) → review+
Landed: http://hg.mozilla.org/mozilla-central/rev/405c1da60c0d
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9.3b2
Verified fixed by landing and green tests.

Dave in which of the schemachange patches you track the bump of the schema version and the database upgrade?
Status: RESOLVED → VERIFIED
Flags: in-testsuite+
Flags: in-litmus-
(In reply to comment #8)
> Dave in which of the schemachange patches you track the bump of the schema
> version and the database upgrade?

Ok, that's bug 455264.
(In reply to comment #9)
> Ok, that's bug 455264.

Sorry, that was the attachment id of the patch. It's bug 558834 for real.
Note, the size of the default theme is not correct: 12.3KB?
Created bug 579831 for this.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: