예제 #1
0
 def test_create_dirs_already_exists_symlink_too(self):
     """test that creating a Main instance works as expected."""
     link = os.path.join(self.root, 'Shared With Me')
     make_link(self.shares, link)
     self.assertTrue(is_link(link))
     self.assertTrue(path_exists(self.shares))
     self.assertTrue(path_exists(self.root))
     main = self.build_main()
     # check that the shares link is actually a link
     self.assertTrue(is_link(main.shares_dir_link))
예제 #2
0
def create_shares_link(source, dest):
    """Create the shares symlink."""
    result = False
    if not path_exists(dest):
        # remove the symlink if it's broken
        if is_link(dest) and read_link(dest) != source:
            remove_link(dest)

        if not is_link(dest):
            # only create the link if it does not exist
            make_link(source, dest)
            result = True
    return result
예제 #3
0
    def test_make_link(self):
        """The link is properly made."""
        destination = os.path.join(self.basedir, 'destination')
        make_link(self.testfile, destination)

        self.assertTrue(is_link(destination))
        self.assertEqual(os.path.normcase(self.testfile),
                         os.path.normcase(read_link(destination)))
예제 #4
0
 def test_create_dirs_none_exists(self):
     """test that creating a Main instance works as expected."""
     # remove the existing dirs
     remove_dir(self.root)
     remove_dir(self.shares)
     main = self.build_main()
     # check that the shares link is actually a link
     self.assertTrue(is_link(main.shares_dir_link))
     self.assertTrue(path_exists(self.shares))
     self.assertTrue(path_exists(self.root))
예제 #5
0
    def validate_path_for_folder(self, folder_path):
        """Validate 'folder_path' for folder creation."""
        user_home = os.path.expanduser('~')
        folder_path = append_path_sep(folder_path)

        # handle folder_path not within '~' or links
        # XXX is_link expects bytes, see bug #824252
        if not folder_path.startswith(user_home) or is_link(
            folder_path.encode('utf-8')):
            returnValue(False)

        # handle folder_path nested with a existing cloud folder
        volumes = yield self.volumes_info(with_storage_info=False)
        for _, _, data in volumes:
            for volume in data:
                cloud_folder = append_path_sep(volume['path'])
                if (folder_path.startswith(cloud_folder) or
                    cloud_folder.startswith(folder_path)):
                    returnValue(False)

        returnValue(True)
예제 #6
0
        def scan():
            """The scan, really."""

            log_debug("scanning the dir %r", dirpath)
            dircontent = listdir(dirpath)

            # get the info from disk
            dnames = []
            fnames = []
            for something in dircontent:
                fullname = os.path.join(dirpath, something)
                stat_result = get_stat(fullname)
                if stat_result is None:
                    # gone between the listdir and now
                    continue
                if is_link(fullname):
                    log_info("Ignoring path as it's a symlink: %r", fullname)
                    continue
                if not is_valid_name(fullname):
                    m = "Ignoring path because it's invalid (non utf8): %r"
                    log_info(m, fullname)
                    continue
                if not access(fullname):
                    log_warning("Ignoring path as we don't have enough "
                                "permissions to track it: %r", fullname)
                    continue

                if stat.S_ISDIR(stat_result.st_mode):
                    dnames.append(something)
                elif stat.S_ISREG(stat_result.st_mode):
                    fnames.append(something)
                else:
                    log_warning("Path: %r isn't a dir, file or symlink.",
                                fullname)

            events, to_scan_later = self._compare(dirpath, dnames, fnames,
                                                  share)
            to_later.extend(to_scan_later)
            return events