~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Robert Collins
  • Date: 2005-09-07 10:47:36 UTC
  • mto: (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050907104736-8e592b72108c577d
symlink support updated to work

Show diffs side-by-side

added added

removed removed

Lines of Context:
100
100
    # directories, etc etc.
101
101
 
102
102
    __slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
103
 
                 'text_id', 'parent_id', 'children', ]
 
103
                 'text_id', 'parent_id', 'children', 'symlink_target']
104
104
 
105
105
    def __init__(self, file_id, name, kind, parent_id, text_id=None):
106
106
        """Create an InventoryEntry
128
128
        self.kind = kind
129
129
        self.text_id = text_id
130
130
        self.parent_id = parent_id
 
131
        self.symlink_target = None
131
132
        if kind == 'directory':
132
133
            self.children = {}
133
134
        elif kind == 'file':
134
135
            pass
 
136
        elif kind == 'symlink':
 
137
            pass
135
138
        else:
136
139
            raise BzrError("unhandled entry kind %r" % kind)
137
140
 
138
 
 
 
141
    def read_symlink_target(self, path):
 
142
        if self.kind == 'symlink':
 
143
            try:
 
144
                self.symlink_target = os.readlink(path)
 
145
            except OSError,e:
 
146
                raise BzrError("os.readlink error, %s" % e)
139
147
 
140
148
    def sorted_children(self):
141
149
        l = self.children.items()
148
156
                               self.parent_id, text_id=self.text_id)
149
157
        other.text_sha1 = self.text_sha1
150
158
        other.text_size = self.text_size
 
159
        other.symlink_target = self.symlink_target
151
160
        # note that children are *not* copied; they're pulled across when
152
161
        # others are added
153
162
        return other
175
184
        if self.text_size != None:
176
185
            e.set('text_size', '%d' % self.text_size)
177
186
            
178
 
        for f in ['text_id', 'text_sha1']:
 
187
        for f in ['text_id', 'text_sha1', 'symlink_target']:
179
188
            v = getattr(self, f)
180
189
            if v != None:
181
190
                e.set(f, v)
205
214
        self = cls(elt.get('file_id'), elt.get('name'), elt.get('kind'), parent_id)
206
215
        self.text_id = elt.get('text_id')
207
216
        self.text_sha1 = elt.get('text_sha1')
 
217
        self.symlink_target = elt.get('symlink_target')
208
218
        
209
219
        ## mutter("read inventoryentry: %r" % (elt.attrib))
210
220
 
222
232
 
223
233
        return (self.file_id == other.file_id) \
224
234
               and (self.name == other.name) \
 
235
               and (other.symlink_target == self.symlink_target) \
225
236
               and (self.text_sha1 == other.text_sha1) \
226
237
               and (self.text_size == other.text_size) \
227
238
               and (self.text_id == other.text_id) \