~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-13 23:16:20 UTC
  • mfrom: (4957 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4960.
  • Revision ID: andrew.bennetts@canonical.com-20100113231620-n6in2yjib2v6z03g
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
202
202
    :param old: The old path, to rename from
203
203
    :param new: The new path, to rename to
204
204
    :param rename_func: The potentially non-atomic rename function
205
 
    :param unlink_func: A way to delete the target file if the full rename succeeds
 
205
    :param unlink_func: A way to delete the target file if the full rename
 
206
        succeeds
206
207
    """
207
 
 
208
208
    # sftp rename doesn't allow overwriting, so play tricks:
209
209
    base = os.path.basename(new)
210
210
    dirname = os.path.dirname(new)
211
 
    tmp_name = u'tmp.%s.%.9f.%d.%s' % (base, time.time(), os.getpid(), rand_chars(10))
 
211
    # callers use different encodings for the paths so the following MUST
 
212
    # respect that. We rely on python upcasting to unicode if new is unicode
 
213
    # and keeping a str if not.
 
214
    tmp_name = 'tmp.%s.%.9f.%d.%s' % (base, time.time(),
 
215
                                      os.getpid(), rand_chars(10))
212
216
    tmp_name = pathjoin(dirname, tmp_name)
213
217
 
214
218
    # Rename the file out of the way, but keep track if it didn't exist