~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Martin Pool
  • Date: 2005-05-12 02:14:35 UTC
  • Revision ID: mbp@sourcefrog.net-20050512021435-87fa19f051842647
- new helper function kind_marker()

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
 
# -*- coding: UTF-8 -*-
 
1
 
3
2
 
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
58
57
    >>> st['123123'].read()
59
58
    'goodbye'
60
59
 
61
 
    :todo: Atomic add by writing to a temporary file and renaming.
 
60
    TODO: Atomic add by writing to a temporary file and renaming.
62
61
 
63
 
    :todo: Perhaps automatically transform to/from XML in a method?
 
62
    TODO: Perhaps automatically transform to/from XML in a method?
64
63
           Would just need to tell the constructor what class to
65
64
           use...
66
65
 
67
 
    :todo: Even within a simple disk store like this, we could
 
66
    TODO: Even within a simple disk store like this, we could
68
67
           gzip the files.  But since many are less than one disk
69
68
           block, that might not help a lot.
70
69
 
83
82
    def add(self, f, fileid, compressed=True):
84
83
        """Add contents of a file into the store.
85
84
 
86
 
        :param f: An open file, or file-like object."""
 
85
        f -- An open file, or file-like object."""
87
86
        # FIXME: Only works on smallish files
88
87
        # TODO: Can be optimized by copying at the same time as
89
88
        # computing the sum.
169
168
 
170
169
    def __del__(self):
171
170
        for f in os.listdir(self._basedir):
172
 
            os.remove(os.path.join(self._basedir, f))
 
171
            fpath = os.path.join(self._basedir, f)
 
172
            # needed on windows, and maybe some other filesystems
 
173
            os.chmod(fpath, 0600)
 
174
            os.remove(fpath)
173
175
        os.rmdir(self._basedir)
174
176
        mutter("%r destroyed" % self)