code: func RenameOrCopy(src, dst fs.Filesystem, from, to string) error {
  	renameLock.Lock()
  	defer renameLock.Unlock()
  
  	return withPreparedTarget(dst, from, to, func() error {
  		// Optimisation 1
  		if src.Type() == dst.Type() && src.URI() == dst.URI() {
  			return src.Rename(from, to)
  		}
  
  		// "Optimisation" 2
  		// Try to find a common prefix between the two filesystems, use that as the base for the new one
  		// and try a rename.
  		if src.Type() == dst.Type() {
  			commonPrefix := fs.CommonPrefix(src.URI(), dst.URI())
  			if len(commonPrefix) > 0 {
  				commonFs := fs.NewFilesystem(src.Type(), commonPrefix)
  				err := commonFs.Rename(
  					filepath.Join(strings.TrimPrefix(src.URI(), commonPrefix), from),
  					filepath.Join(strings.TrimPrefix(dst.URI(), commonPrefix), to),
  				)
  				if err == nil {
  					return nil
  				}
  			}
  		}
  
  		// Everything is sad, do a copy and delete.
  		if _, err := dst.Stat(to); !fs.IsNotExist(err) {
  			err := dst.Remove(to)
  			if err != nil {
  				return err
  			}
  		}
  
  		err := copyFileContents(src, dst, from, to)
  		if err != nil {
  			_ = dst.Remove(to)
  			return err
  		}
  
  		return withPreparedTarget(src, from, from, func() error {
  			return src.Remove(from)
  		})
  	})
  }
docs: // RenameOrCopy renames a file, leaving source file intact in case of failure.
  // Tries hard to succeed on various systems by temporarily tweaking directory
  // permissions and removing the destination file when necessary.