Revision d065f612 pithos/backends/simple.py

b/pithos/backends/simple.py
70 70
    Uses SQLite for storage.
71 71
    """
72 72
    
73
    # TODO: Create account if not present in all functions.
74
    
73 75
    def __init__(self, db):
74 76
        self.hash_algorithm = 'sha256'
75 77
        self.block_size = 4 * 1024 * 1024 # 4MB
......
145 147
        if user != account:
146 148
            if until or account not in self._allowed_accounts(user):
147 149
                raise NotAllowedError
150
        else:
151
            self._create_account(user, account)
148 152
        try:
149 153
            version_id, mtime = self._get_accountinfo(account, until)
150 154
        except NameError:
155
            # TODO: Make sure this doesn't happen.
151 156
            version_id = None
152 157
            mtime = 0
153 158
        count, bytes, tstamp = self._get_pathstats(account, until)
......
174 179
            meta.update({'name': account, 'count': count, 'bytes': bytes})
175 180
            if until is not None:
176 181
                meta.update({'until_timestamp': tstamp})
177
        if modified:
178
            meta.update({'modified': modified})
182
        meta.update({'modified': modified})
179 183
        return meta
180 184
    
181 185
    @backend_method
......
196 200
            if account not in self._allowed_accounts(user):
197 201
                raise NotAllowedError
198 202
            return {}
203
        self._create_account(user, account)
199 204
        return self._get_groups(account)
200 205
    
201 206
    @backend_method
......
205 210
        logger.debug("update_account_groups: %s %s %s", account, groups, replace)
206 211
        if user != account:
207 212
            raise NotAllowedError
213
        self._create_account(user, account)
208 214
        self._check_groups(groups)
209 215
        self._put_groups(account, groups, replace)
210 216
    
......
221 227
            pass
222 228
        else:
223 229
            raise NameError('Account already exists')
224
        version_id = self._put_version(account, user)
230
        self._put_version(account, user)
225 231
    
226 232
    @backend_method
227 233
    def delete_account(self, user, account):
......
338 344
        if policy:
339 345
            self._check_policy(policy)
340 346
        path = os.path.join(account, container)
341
        version_id = self._put_version(path, user)
347
        version_id = self._put_version(path, user)[0]
342 348
        for k, v in self.default_policy.iteritems():
343 349
            if k not in policy:
344 350
                policy[k] = v
......
661 667
        tstamp = int(time.time())
662 668
        sql = 'insert into versions (name, user, tstamp, size, hide) values (?, ?, ?, ?, ?)'
663 669
        id = self.con.execute(sql, (path, user, tstamp, size, hide)).lastrowid
664
        return str(id)
670
        return str(id), tstamp
665 671
    
666 672
    def _copy_version(self, user, src_path, dest_path, copy_meta=True, copy_data=True, src_version=None):
667 673
        if src_version is not None:
......
675 681
                size = 0
676 682
        if not copy_data:
677 683
            size = 0
678
        dest_version_id = self._put_version(dest_path, user, size)
684
        dest_version_id = self._put_version(dest_path, user, size)[0]
679 685
        if copy_meta and src_version_id is not None:
680 686
            sql = 'insert into metadata select %s, key, value from metadata where version_id = ?'
681 687
            sql = sql % dest_version_id
......
722 728
        version_id, muser, mtime, size = self._get_version(path, version)
723 729
        return path, version_id, muser, mtime, size
724 730
    
731
    def _create_account(self, user, account):
732
        try:
733
            self._get_accountinfo(account)
734
        except NameError:
735
            self._put_version(account, user)
736
    
725 737
    def _get_metadata(self, path, version):
726 738
        sql = 'select key, value from metadata where version_id = ?'
727 739
        c = self.con.execute(sql, (version,))
......
759 771
        c = self.con.execute(sql, (path,))
760 772
        return dict(c.fetchall())
761 773
    
762
    
763 774
    def _list_limits(self, listing, marker, limit):
764 775
        start = 0
765 776
        if marker:

Also available in: Unified diff