/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 breezy/plugins/upload/cmds.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-09-22 02:38:35 UTC
  • mfrom: (7058.5.4 upload-symlin)
  • Revision ID: breezy.the.bot@gmail.com-20180922023835-wb9nczxp63jpeudb
Add symlink support to 'brz upload'.

Merged from https://code.launchpad.net/~jelmer/brz/upload-symlinks/+merge/355061

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    config,
25
25
    lazy_import,
26
26
    option,
 
27
    osutils,
27
28
    )
28
29
lazy_import.lazy_import(globals(), """
29
30
import stat
184
185
            self.outf.write('Uploading %s\n' % old_relpath)
185
186
        self._up_put_bytes(old_relpath, self.tree.get_file_text(new_relpath, id), mode)
186
187
 
 
188
    def _force_clear(self, relpath):
 
189
        try:
 
190
            st = self._up_stat(relpath)
 
191
            if stat.S_ISDIR(st.st_mode):
 
192
                # A simple rmdir may not be enough
 
193
                if not self.quiet:
 
194
                    self.outf.write('Clearing %s/%s\n' % (
 
195
                            self.to_transport.external_url(), relpath))
 
196
                self._up_delete_tree(relpath)
 
197
            elif stat.S_ISLNK(st.st_mode):
 
198
                if not self.quiet:
 
199
                    self.outf.write('Clearing %s/%s\n' % (
 
200
                        self.to_transport.external_url(), relpath))
 
201
                self._up_delete(relpath)
 
202
        except errors.PathError:
 
203
            pass
 
204
 
187
205
    def upload_file_robustly(self, relpath, id, mode=None):
188
206
        """Upload a file, clearing the way on the remote side.
189
207
 
190
208
        When doing a full upload, it may happen that a directory exists where
191
209
        we want to put our file.
192
210
        """
193
 
        try:
194
 
            st = self._up_stat(relpath)
195
 
            if stat.S_ISDIR(st.st_mode):
196
 
                # A simple rmdir may not be enough
197
 
                if not self.quiet:
198
 
                    self.outf.write('Clearing %s/%s\n' % (
199
 
                            self.to_transport.external_url(), relpath))
200
 
                self._up_delete_tree(relpath)
201
 
        except errors.PathError:
202
 
            pass
 
211
        self._force_clear(relpath)
203
212
        self.upload_file(relpath, relpath, id, mode)
204
213
 
 
214
    def upload_symlink(self, relpath, target):
 
215
        self.to_transport.symlink(target, relpath)
 
216
 
 
217
    def upload_symlink_robustly(self, relpath, target):
 
218
        """Handle uploading symlinks.
 
219
        """
 
220
        self._force_clear(relpath)
 
221
        # Target might not be there at this time; dummy file should be
 
222
        # overwritten at some point, possibly by another upload.
 
223
        target = osutils.normpath(osutils.pathjoin(
 
224
            osutils.dirname(relpath),
 
225
            target)
 
226
        )
 
227
        self.upload_symlink(relpath, target)
 
228
 
205
229
    def make_remote_dir(self, relpath, mode=None):
206
230
        if mode is None:
207
231
            mode = 0o775
303
327
                    continue
304
328
                if ie.kind == 'file':
305
329
                    self.upload_file_robustly(relpath, ie.file_id)
 
330
                elif ie.kind == 'symlink':
 
331
                    try:
 
332
                        self.upload_symlink_robustly(relpath, ie.symlink_target)
 
333
                    except errors.TransportNotPossible:
 
334
                        if not self.quiet:
 
335
                            target = self.tree.path_content_summary(relpath)[3]
 
336
                            self.outf.write('Not uploading symlink %s -> %s\n'
 
337
                                            % (relpath, target))
306
338
                elif ie.kind == 'directory':
307
339
                    self.make_remote_dir_robustly(relpath)
308
 
                elif ie.kind == 'symlink':
309
 
                    if not self.quiet:
310
 
                        target = self.tree.path_content_summary(relpath)[3]
311
 
                        self.outf.write('Not uploading symlink %s -> %s\n'
312
 
                                        % (relpath, target))
313
340
                else:
314
341
                    raise NotImplementedError
315
342
            self.set_uploaded_revid(self.rev_id)
347
374
                elif kind is  'directory':
348
375
                    self.delete_remote_dir_maybe(path)
349
376
                elif kind == 'symlink':
350
 
                    if not self.quiet:
351
 
                        target = self.tree.path_content_summary(path)[3]
352
 
                        self.outf.write('Not deleting remote symlink %s -> %s\n'
353
 
                                        % (path, target))
 
377
                    self.delete_remote_file(path)
354
378
                else:
355
379
                    raise NotImplementedError
356
380
 
365
389
                    # We update the old_path content because renames and
366
390
                    # deletions are differed.
367
391
                    self.upload_file(old_path, new_path, id)
368
 
                if kind == 'symlink':
369
 
                    if not self.quiet:
370
 
                        self.outf.write('Not renaming remote symlink %s to %s\n'
371
 
                                        % (old_path, new_path))
372
 
                else:
373
 
                    self.rename_remote(old_path, new_path)
 
392
                self.rename_remote(old_path, new_path)
374
393
            self.finish_renames()
375
394
            self.finish_deletions()
376
395
 
379
398
                    if not self.quiet:
380
399
                        self.outf.write('Ignoring %s\n' % path)
381
400
                    continue
382
 
                if old_kind == 'file':
 
401
                if old_kind in ('file', 'symlink'):
383
402
                    self.delete_remote_file(path)
384
 
                elif old_kind ==  'directory':
 
403
                elif old_kind == 'directory':
385
404
                    self.delete_remote_dir(path)
386
405
                else:
387
406
                    raise NotImplementedError
388
407
 
389
408
                if new_kind == 'file':
390
409
                    self.upload_file(path, path, id)
 
410
                elif new_kind == 'symlink':
 
411
                    target = self.tree.get_symlink_target(path)
 
412
                    self.upload_symlink(path, target)
391
413
                elif new_kind is 'directory':
392
414
                    self.make_remote_dir(path)
393
415
                else:
403
425
                elif kind == 'directory':
404
426
                    self.make_remote_dir(path)
405
427
                elif kind == 'symlink':
406
 
                    if not self.quiet:
407
 
                        target = self.tree.path_content_summary(path)[3]
408
 
                        self.outf.write('Not uploading symlink %s -> %s\n'
409
 
                                        % (path, target))
 
428
                    target = self.tree.get_symlink_target(path)
 
429
                    try:
 
430
                        self.upload_symlink(path, target)
 
431
                    except errors.TransportNotPossible:
 
432
                        if not self.quiet:
 
433
                            self.outf.write('Not uploading symlink %s -> %s\n'
 
434
                                            % (path, target))
410
435
                else:
411
436
                    raise NotImplementedError
412
437
 
419
444
                    continue
420
445
                if kind == 'file':
421
446
                    self.upload_file(path, path, id)
 
447
                elif kind == 'symlink':
 
448
                    target = self.tree.get_symlink_target(path)
 
449
                    self.upload_symlink(path, target)
422
450
                else:
423
451
                    raise NotImplementedError
424
452
 
542
570
            locked.unlock()
543
571
 
544
572
        # We uploaded successfully, remember it
545
 
        branch.lock_write()
546
 
        try:
 
573
        with branch.lock_write():
547
574
            upload_location = conf.get('upload_location')
548
575
            if upload_location is None or remember:
549
576
                conf.set('upload_location',
550
577
                         urlutils.unescape(to_transport.base))
551
578
            if auto is not None:
552
579
                conf.set('upload_auto', auto)
553
 
        finally:
554
 
            branch.unlock()
555
580