~ubuntu-branches/ubuntu/lucid/ubuntuone-client/lucid-updates

« back to all changes in this revision

Viewing changes to ubuntuone/syncdaemon/filesystem_manager.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2009-10-16 13:35:00 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091016133500-t2zacp5ozfj1hpug
Tags: 1.0.2-0ubuntu1
* New upstream release.
  - Avoid conflicts due to bouncing FS events (LP: #449605)
  - Don't try to authorize if connect on start is never (LP: #451154)

Show diffs side-by-side

added added

removed removed

Lines of Context:
221
221
                                    cache_compact_threshold=4)
222
222
        self.shares = {}
223
223
        self.vm = vm
 
224
        self.eq = None  # this will be registered later
224
225
 
225
226
        # create the indexes
226
227
        self._idx_path = {}
244
245
        logger("initialized: idx_path: %s, idx_node_id: %s, shares: %s" %
245
246
               (len(self._idx_path), len(self._idx_node_id), len(self.shares)))
246
247
 
 
248
    def register_eq(self, eq):
 
249
        '''Registers an EventQueue here.'''
 
250
        self.eq = eq
 
251
 
247
252
    def _safe_fs_iteritems(self):
248
 
        """returns a 'safe' iterator over the items of the FileShelf.
249
 
        it's 'safe' because broked metadata objects are deleted and not
 
253
        """Returns a 'safe' iterator over the items of the FileShelf.
 
254
 
 
255
        It's 'safe' because broken metadata objects are deleted and not
250
256
        returned.
251
257
        """
252
258
        def safeget_mdobj(mdid):
566
572
        # pylint: disable-msg=W0704
567
573
        try:
568
574
            with contextlib.nested(from_context, to_context):
 
575
                if mdobj["is_dir"]:
 
576
                    expected_event = "FS_DIR_MOVE"
 
577
                else:
 
578
                    expected_event = "FS_FILE_MOVE"
 
579
                self.eq.add_to_mute_filter(expected_event, path_from, path_to)
569
580
                shutil.move(path_from, path_to)
570
581
        except IOError, e:
571
582
            # file was not yet created
652
663
        try:
653
664
            with self._enable_share_write(mdobj['share_id'], path):
654
665
                if self.is_dir(path=path):
 
666
                    self.eq.add_to_mute_filter("FS_DIR_DELETE", path)
655
667
                    os.rmdir(path)
656
668
                else:
 
669
                    self.eq.add_to_mute_filter("FS_FILE_DELETE", path)
657
670
                    os.remove(path)
658
671
        except OSError, e:
659
672
            if e.errno == errno.ENOTEMPTY:
674
687
            to_path = base_to_path + "." + str(ind)
675
688
        with self._enable_share_write(mdobj['share_id'], path):
676
689
            try:
 
690
                if mdobj["is_dir"]:
 
691
                    expected_event = "FS_DIR_MOVE"
 
692
                else:
 
693
                    expected_event = "FS_FILE_MOVE"
 
694
                self.eq.add_to_mute_filter(expected_event, path, to_path)
677
695
                os.rename(path, to_path)
678
696
            except OSError, e:
679
697
                if e.errno == errno.ENOENT:
739
757
        with self._enable_share_write(share_id, os.path.dirname(path)):
740
758
            # if we don't have the dir yet, create it
741
759
            if is_dir and not os.path.exists(path):
 
760
                self.eq.add_to_mute_filter("FS_DIR_CREATE", path)
742
761
                os.mkdir(path)
 
762
 
 
763
        # don't alert EQ, partials are in other directory, not watched
743
764
        open(partial_path, "w").close()
744
765
        mdobj["info"]["last_partial_created"] = time.time()
745
766
        mdobj["info"]["is_partial"] = True
786
807
 
787
808
        partial_path = self._get_partial_path(mdobj)
788
809
        with self._enable_share_write(share_id, path):
 
810
            self.eq.add_to_mute_filter("FS_FILE_CREATE", path)
 
811
            self.eq.add_to_mute_filter("FS_FILE_CLOSE_WRITE", path)
789
812
            shutil.move(partial_path, path)
790
813
        mdobj["local_hash"] = local_hash
791
814
        mdobj["info"]["last_downloaded"] = time.time()
805
828
        partial_path = self._get_partial_path(mdobj)
806
829
        #pylint: disable-msg=W0704
807
830
        try:
 
831
            # don't alert EQ, partials are in other directory, not watched
808
832
            os.remove(partial_path)
809
833
        except OSError, e:
810
834
            # we only remove it if its there.