(self, before, after)
args are the same as in self.report_conflicts
        If before and after differ, try to do actual rename for each pair
        Take into account directory symlinks on Unix-like OSes (they cannot be just renamed)
        In case of error, show message and exit skipping remain pairs
args are the same as in self.report_conflicts
        If before and after differ, try to do actual rename for each pair
        Take into account directory symlinks on Unix-like OSes (they cannot be just renamed)
        In case of error, show message and exit skipping remain pairs
args are the same as in self . report_conflicts If before and after differ try to do actual rename for each pair Take into account directory symlinks on Unix - like OSes ( they cannot be just renamed ) In case of error show message and exit skipping remain pairs
def apply_renames(self, before, after):
        '''args are the same as in self.report_conflicts
        If before and after differ, try to do actual rename for each pair
        Take into account directory symlinks on Unix-like OSes (they cannot be just renamed)
        In case of error, show message and exit skipping remain pairs
        '''
        # reverse order to allow renaming child and parent at the same time (tree view)
        diffs = list(reversed([(b, a) for (b, a) in zip(before, after) if b != a]))
        if not diffs:
            return sublime.status_message('Exit rename mode, no changes')

        path = self.path
        existing = set(before)
        while diffs:
            b, a = diffs.pop(0)

            if a in existing:
                # There is already a file with this name.  Give it a temporary name (in
                # case of cycles like "x->z and z->x") and put it back on the list.
                tmp = tempfile.NamedTemporaryFile(delete=False, dir=path).name
                os.unlink(tmp)
                diffs.append((tmp, a))
                a = tmp

            print(u'FileBrowser rename: {0} → {1}'.format(b, a))
            orig = join(path, b)
            if orig[~0] == '/' and os.path.islink(orig[:~0]):
                # last slash shall be omitted; file has no last slash,
                # thus it False and symlink to file shall be os.rename'd
                dest = os.readlink(orig[:~0])
                os.unlink(orig[:~0])
                os.symlink(dest, join(path, a)[:~0])
            else:
                try:
                    os.rename(orig, join(path, a))
                except OSError:
                    msg = (u'FileBrowser:\n\nError is occurred during renaming.\n'
                           u'Please, fix it and apply changes or cancel renaming.\n\n'
                           u'\t {0} → {1}\n\n'
                           u'Don’t rename\n'
                           u'  • non-existed file (cancel renaming to refresh)\n'
                           u'  • file if you’re not owner'
                           u'  • disk letter on Windows\n'.format(b, a))
                    sublime.error_message(msg)
                    return
            existing.remove(b)
            existing.add(a)
def apply_renames ( self , before , after ) : # reverse order to allow renaming child and parent at the same time (tree view) diffs = list ( reversed ( [ ( b , a ) for ( b , a ) in zip ( before , after ) if b != a ] ) ) if not diffs : return sublime . status_message ( 'Exit rename mode, no changes' ) path = self . path existing = set ( before ) while diffs : b , a = diffs . pop ( 0 ) if a in existing : # There is already a file with this name.  Give it a temporary name (in # case of cycles like "x->z and z->x") and put it back on the list. tmp = tempfile . NamedTemporaryFile ( delete = False , dir = path ) . name os . unlink ( tmp ) diffs . append ( ( tmp , a ) ) a = tmp print ( u'FileBrowser rename: {0} → {1}'.f o rmat(b , a ) orig = join ( path , b ) if orig [ ~ 0 ] == '/' and os . path . islink ( orig [ : ~ 0 ] ) : # last slash shall be omitted; file has no last slash, # thus it False and symlink to file shall be os.rename'd dest = os . readlink ( orig [ : ~ 0 ] ) os . unlink ( orig [ : ~ 0 ] ) os . symlink ( dest , join ( path , a ) [ : ~ 0 ] ) else : try : os . rename ( orig , join ( path , a ) ) except OSError : msg = ( u'FileBrowser:\n\nError is occurred during renaming.\n' u'Please, fix it and apply changes or cancel renaming.\n\n' u'\t {0} → {1}\n\n' u'Don’t rename\n' u'  • non-existed file (cancel renaming to refresh)\n' u'  • file if you’re not owner' u'  • disk letter on Windows\n'.f o rmat(b , a ) sublime . error_message ( msg ) return existing . remove ( b ) existing . add ( a )