/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/local.py

  • Committer: Robert Collins
  • Date: 2006-06-09 09:18:56 UTC
  • mfrom: (1725.2.9 commit)
  • mto: This revision was merged to the branch mainline in revision 1757.
  • Revision ID: robertc@robertcollins.net-20060609091856-2f9fc48998d655a9
(robertc, ab)Merge some commit and fetch tuning steps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
        else:
65
65
            return LocalTransport(self.abspath(offset))
66
66
 
 
67
    def _abspath(self, relative_reference):
 
68
        """Return a path for use in os calls.
 
69
 
 
70
        Several assumptions are made:
 
71
         - relative_reference does not contain '..'
 
72
         - relative_reference is url escaped.
 
73
        """
 
74
        return self._local_base + urlutils.unescape(relative_reference)
 
75
 
67
76
    def abspath(self, relpath):
68
77
        """Return the full url to the given relative URL."""
 
78
        # TODO: url escape the result. RBC 20060523.
69
79
        assert isinstance(relpath, basestring), (type(relpath), relpath)
70
80
        # jam 20060426 Using normpath on the real path, because that ensures
71
81
        #       proper handling of stuff like
79
89
        the only one that has direct local access.
80
90
        This is mostly for stuff like WorkingTree which needs to know
81
91
        the local working directory.
 
92
        
 
93
        This function is quite expensive: it calls realpath which resolves
 
94
        symlinks.
82
95
        """
83
96
        absurl = self.abspath(relpath)
84
97
        # mutter(u'relpath %s => base: %s, absurl %s', relpath, self.base, absurl)
95
108
            urlutils.strip_trailing_slash(abspath))
96
109
 
97
110
    def has(self, relpath):
98
 
        return os.access(self.local_abspath(relpath), os.F_OK)
 
111
        return os.access(self._abspath(relpath), os.F_OK)
99
112
 
100
113
    def get(self, relpath):
101
114
        """Get the file at the given relative path.
103
116
        :param relpath: The relative path to the file
104
117
        """
105
118
        try:
106
 
            path = self.local_abspath(relpath)
107
 
            # mutter('LocalTransport.get(%r) => %r', relpath, path)
 
119
            path = self._abspath(relpath)
108
120
            return open(path, 'rb')
109
121
        except (IOError, OSError),e:
110
122
            self._translate_error(e, path)
119
131
 
120
132
        path = relpath
121
133
        try:
122
 
            path = self.local_abspath(relpath)
 
134
            path = self._abspath(relpath)
123
135
            check_legal_path(path)
124
136
            fp = AtomicFile(path, 'wb', new_mode=mode)
125
137
        except (IOError, OSError),e:
146
158
        """Create a directory at the given path."""
147
159
        path = relpath
148
160
        try:
149
 
            path = self.local_abspath(relpath)
 
161
            path = self._abspath(relpath)
150
162
            os.mkdir(path)
151
163
            if mode is not None:
152
164
                os.chmod(path, mode)
154
166
            self._translate_error(e, path)
155
167
 
156
168
    def append(self, relpath, f, mode=None):
157
 
        """Append the text in the file-like object into the final
158
 
        location.
159
 
        """
 
169
        """Append the text in the file-like object into the final location."""
 
170
        abspath = self._abspath(relpath)
160
171
        try:
161
 
            fp = open(self.local_abspath(relpath), 'ab')
 
172
            fp = open(abspath, 'ab')
 
173
            # FIXME should we really be chmodding every time ? RBC 20060523
162
174
            if mode is not None:
163
 
                os.chmod(self.local_abspath(relpath), mode)
 
175
                os.chmod(abspath, mode)
164
176
        except (IOError, OSError),e:
165
177
            self._translate_error(e, relpath)
166
178
        # win32 workaround (tell on an unwritten file returns 0)
171
183
 
172
184
    def copy(self, rel_from, rel_to):
173
185
        """Copy the item at rel_from to the location at rel_to"""
174
 
        path_from = self.local_abspath(rel_from)
175
 
        path_to = self.local_abspath(rel_to)
 
186
        path_from = self._abspath(rel_from)
 
187
        path_to = self._abspath(rel_to)
176
188
        try:
177
189
            shutil.copy(path_from, path_to)
178
190
        except (IOError, OSError),e:
180
192
            self._translate_error(e, path_from)
181
193
 
182
194
    def rename(self, rel_from, rel_to):
183
 
        path_from = self.local_abspath(rel_from)
 
195
        path_from = self._abspath(rel_from)
184
196
        try:
185
197
            # *don't* call bzrlib.osutils.rename, because we want to 
186
198
            # detect errors on rename
187
 
            os.rename(path_from, self.local_abspath(rel_to))
 
199
            os.rename(path_from, self._abspath(rel_to))
188
200
        except (IOError, OSError),e:
189
201
            # TODO: What about path_to?
190
202
            self._translate_error(e, path_from)
191
203
 
192
204
    def move(self, rel_from, rel_to):
193
205
        """Move the item at rel_from to the location at rel_to"""
194
 
        path_from = self.local_abspath(rel_from)
195
 
        path_to = self.local_abspath(rel_to)
 
206
        path_from = self._abspath(rel_from)
 
207
        path_to = self._abspath(rel_to)
196
208
 
197
209
        try:
198
210
            # this version will delete the destination if necessary
205
217
        """Delete the item at relpath"""
206
218
        path = relpath
207
219
        try:
208
 
            path = self.local_abspath(relpath)
 
220
            path = self._abspath(relpath)
209
221
            os.remove(path)
210
222
        except (IOError, OSError),e:
211
 
            # TODO: What about path_to?
212
223
            self._translate_error(e, path)
213
224
 
214
225
    def copy_to(self, relpaths, other, mode=None, pb=None):
225
236
            for path in relpaths:
226
237
                self._update_pb(pb, 'copy-to', count, total)
227
238
                try:
228
 
                    mypath = self.local_abspath(path)
229
 
                    otherpath = other.local_abspath(path)
 
239
                    mypath = self._abspath(path)
 
240
                    otherpath = other._abspath(path)
230
241
                    shutil.copy(mypath, otherpath)
231
242
                    if mode is not None:
232
243
                        os.chmod(otherpath, mode)
246
257
        WARNING: many transports do not support this, so trying avoid using
247
258
        it if at all possible.
248
259
        """
249
 
        path = self.local_abspath(relpath)
 
260
        path = self._abspath(relpath)
250
261
        try:
251
262
            return [urlutils.escape(entry) for entry in os.listdir(path)]
252
263
        except (IOError, OSError), e:
257
268
        """
258
269
        path = relpath
259
270
        try:
260
 
            path = self.local_abspath(relpath)
 
271
            path = self._abspath(relpath)
261
272
            return os.stat(path)
262
273
        except (IOError, OSError),e:
263
274
            self._translate_error(e, path)
269
280
        from bzrlib.lock import ReadLock
270
281
        path = relpath
271
282
        try:
272
 
            path = self.local_abspath(relpath)
 
283
            path = self._abspath(relpath)
273
284
            return ReadLock(path)
274
285
        except (IOError, OSError), e:
275
286
            self._translate_error(e, path)
281
292
        :return: A lock object, which should be passed to Transport.unlock()
282
293
        """
283
294
        from bzrlib.lock import WriteLock
284
 
        return WriteLock(self.local_abspath(relpath))
 
295
        return WriteLock(self._abspath(relpath))
285
296
 
286
297
    def rmdir(self, relpath):
287
298
        """See Transport.rmdir."""
288
299
        path = relpath
289
300
        try:
290
 
            path = self.local_abspath(relpath)
 
301
            path = self._abspath(relpath)
291
302
            os.rmdir(path)
292
303
        except (IOError, OSError),e:
293
304
            self._translate_error(e, path)