newly cloned projects will have their file space added to the amount used
authorKevin Dangoor <kdangoor@mozilla.com>
Fri, 10 Apr 2009 15:15:39 -0400
changeset 1074 a307f9666f971acf9d8d703cb09364edc8dbb18e
parent 1073 1a399ba8a9975d0046ecde8833299c16fd0e4427
child 1076 27403fea2c1c3505f0c6beeac33d814754a20d0f
push id563
push userkdangoor@mozilla.com
push dateFri, 10 Apr 2009 19:15:44 +0000
newly cloned projects will have their file space added to the amount used for the user and, more importantly, have their search indexes updated.
backend/python/bespin/model.py
backend/python/bespin/vcs.py
--- a/backend/python/bespin/model.py
+++ b/backend/python/bespin/model.py
@@ -189,19 +189,18 @@ class User(Base):
         
     def recompute_files(self):
         """Recomputes how much space the user has used."""
         total = 0
         # add up all of the directory contents
         # by only looking at directories, we skip
         # over our metadata files
         for proj in self.projects:
-            additional, files = _get_file_list(proj.location)
+            additional = proj.scan_files()
             total += additional
-            proj._save_file_list(files)
         self.amount_used = total
 
     def mark_opened(self, file_obj, mode):
         """Keeps track of this file as being currently open by the
         user with the mode provided."""
         statusfile = self.statusfile
         try:
             lock = Lock(statusfile)
@@ -1240,18 +1239,22 @@ class Project(object):
         if new_location.exists():
             raise FileConflict("Cannot rename project %s to %s, because"
                 " a project with the new name already exists."
                 % (self.name, new_name))
         old_location.rename(new_location)
         self.name = new_name
         self.location = new_location
         
-    def _save_file_list(self, files):
+    def scan_files(self):
+        """Looks through the files, computes how much space they
+        take and updates the cached file list."""
+        space_used, files = _get_file_list(self.location)
         self.metadata.cache_replace(files)
+        return space_used
         
     def search_files(self, query, limit=20):
         """Scans the files for filenames that match the queries."""
         
         # make the query lower case so that the match boosting
         # in _SearchMatch can use it
         query = query.lower()
         escaped_query = [re.escape(char) for char in query]
--- a/backend/python/bespin/vcs.py
+++ b/backend/python/bespin/vcs.py
@@ -139,16 +139,19 @@ def _clone_impl(user, source, dest=None,
         keychain.set_credentials_for_project(project, remoteauth, username, 
                 password)
     
     metadata = project.metadata
     metadata['remote_url'] = source
 
     if push:
         metadata['push'] = push
+    
+    space_used = project.scan_files()
+    user.amount_used += space_used
 
     metadata.close()
     
     result = dict(output=str(output), command="clone",
                     project=command.dest)
     return result
     
 def run_command(user, project, args, kcpass=None):