Hard link file from ``src`` to ``chroot/dst`` with optional label.

    May raise anything os.link can raise, e.g.
      IOError(Errno 21 'EISDIR')

    May raise ChrootTaggingException if dst is already in a fileset
    but with a different label.
509651
def link(self, src, dst, label=None):
    
    dst = self._normalize(dst)
    self._tag(dst, label)
    self._ensure_parent(dst)
    abs_src = src
    abs_dst = os.path.join(self.chroot, dst)
    safe_copy(abs_src, abs_dst, overwrite=False)
935554
def get_src_or_dst_path(prompt, count):
    
    _path = ""
    print(prompt)
    option = input("Option: ")
    print("\n")
    if option == '1':
        # Set the path to the system desktop folder.
        logger_directory.info("1: desktop")
        _path = os.path.expanduser('~/Desktop')
    elif option == '2':
        # Set the path to the system downloads folder.
        logger_directory.info("2: downloads")
        _path = os.path.expanduser('~/Downloads')
    elif option == '3':
        # Current directory
        logger_directory.info("3: current")
        _path = os.getcwd()
    elif option == '4':
        # Open up the GUI browse dialog
        logger_directory.info("4: browse ")
        _path = browse_dialog_dir()

    else:
        # Something went wrong. Prompt again. Give a couple tries before defaulting to downloads folder
        if count == 2:
            logger_directory.warn("too many attempts")
            print("Too many failed attempts. Defaulting to current working directory.")
            _path = os.getcwd()
        else:
            count += 1
            logger_directory.warn("failed attempts: {}".format(count))
            print("Invalid option. Try again.")

    return _path, count
1120535
def cp(src_path, dst_path, follow_links=False, recursive=True):
    
    successful = False
    try:
        if follow_links and os.path.islink(src_path):
            src_path = os.path.realpath(src_path)
        if follow_links and os.path.islink(dst_path):
            dst_path = os.path.realpath(dst_path)
        if os.path.isdir(src_path):
            if not recursive:
                return successful
            shutil.copytree(src_path, dst_path, symlinks=follow_links)
            successful = True
        elif os.path.exists(src_path):
            if os.path.isdir(dst_path):
                dst_path = os.path.join(dst_path, os.path.basename(src_path))
            shutil.copy2(src_path, dst_path)
            successful = True
        else:
            log.error('cp: source not found: %s' % src_path)
    except (OSError, TypeError) as error:
        log.error('cp: execute failed: %s => %s (%s)' % (src_path, dst_path, error))
    return successful
712524
def from_filename(cls, path_string, origin=MISSING, **kwargs):
        
        path = Path(path_string)
        return cls.from_path(path, origin, **kwargs)
415421
def touch(self, dst, label=None):
    
    dst = self._normalize(dst)
    self._tag(dst, label)
    touch(os.path.join(self.chroot, dst))
1009309
def url2tmp(self, root, url):
        
        filename = url.rsplit('/', 1)[-1]
        return os.path.join(root, filename)
1276707
private void copyToLocal(final FileSystem srcFS, final Path src,
                           final File dst, final boolean copyCrc)
    throws IOException {
    /* Keep the structure similar to ChecksumFileSystem.copyToLocal(). 
     * Ideal these two should just invoke FileUtil.copy() and not repeat
     * recursion here. Of course, copy() should support two more options :
     * copyCrc and useTmpFile (may be useTmpFile need not be an option).
     */
    
    if (!srcFS.getFileStatus(src).isDir()) {
      if (dst.exists()) {
        // match the error message in FileUtil.checkDest():
        throw new IOException("Target " + dst + " already exists");
      }
      
      // use absolute name so that tmp file is always created under dest dir
      File tmp = FileUtil.createLocalTempFile(dst.getAbsoluteFile(),
                                              COPYTOLOCAL_PREFIX, true);
      if (!FileUtil.copy(srcFS, src, tmp, false, srcFS.getConf())) {
        throw new IOException("Failed to copy " + src + " to " + dst); 
      }
      
      if (!tmp.renameTo(dst)) {
        throw new IOException("Failed to rename tmp file " + tmp + 
                              " to local destination \"" + dst + "\".");
      }

      if (copyCrc) {
        if (!(srcFS instanceof ChecksumFileSystem)) {
          throw new IOException("Source file system does not have crc files");
        }
        
        ChecksumFileSystem csfs = (ChecksumFileSystem) srcFS;
        File dstcs = FileSystem.getLocal(srcFS.getConf())
          .pathToFile(csfs.getChecksumFile(new Path(dst.getCanonicalPath())));
        copyToLocal(csfs.getRawFileSystem(), csfs.getChecksumFile(src),
                    dstcs, false);
      } 
    } else {
      // once FileUtil.copy() supports tmp file, we don't need to mkdirs().
      dst.mkdirs();
      for(FileStatus path : srcFS.listStatus(src)) {
        copyToLocal(srcFS, path.getPath(), 
                    new File(dst, path.getPath().getName()), copyCrc);
      }
    }
  }
530569
def copy_folder_content(src, dst):
    
    for file in os.listdir(src):
        file_path = os.path.join(src, file)
        dst_file_path = os.path.join(dst, file)
        if os.path.isdir(file_path):
            shutil.copytree(file_path, dst_file_path)
        else:
            shutil.copyfile(file_path, dst_file_path)
631669
public void moveToLocalFile(Path src, Path dst) throws IOException {
    copyToLocalFile(true, false, src, dst);
  }
1129365
def copy_or_replace(src, dst):
    '''
    '''
    try:
        shutil.copy(src, dst)
    except (OSError, IOError), e:
        # It's possible that the file existed, but was owned by someone
        # else - in that situation, shutil.copy might then fail when it
        # tries to copy perms.
        # However, it's possible that we have write perms to the dir -
        # in which case, we can just delete and replace
        import errno

        if e.errno == errno.EPERM:
            import tempfile
            # try copying into a temporary location beside the old
            # file - if we have perms to do that, we should have perms
            # to then delete the old file, and move the new one into
            # place
            if os.path.isdir(dst):
                dst = os.path.join(dst, os.path.basename(src))

            dst_dir, dst_name = os.path.split(dst)
            dst_temp = tempfile.mktemp(prefix=dst_name + '.', dir=dst_dir)
            shutil.copy(src, dst_temp)
            if not os.path.isfile(dst_temp):
                raise RuntimeError(
                    "shutil.copy completed successfully, but path"
                    " '%s' still did not exist" % dst_temp)
            os.remove(dst)
            shutil.move(dst_temp, dst)
410428
private void transferLinks(LinkedHashMapEntry<K,V> src,
                               LinkedHashMapEntry<K,V> dst) {
        LinkedHashMapEntry<K,V> b = dst.before = src.before;
        LinkedHashMapEntry<K,V> a = dst.after = src.after;
        if (b == null)
            head = dst;
        else
            b.after = dst;
        if (a == null)
            tail = dst;
        else
            a.before = dst;
    }
1050002
public boolean hardLink(String src, String dst) throws IOException {  
    checkOpen();  
    try { 
      return namenode.hardLink(src, dst); 
    } catch(RemoteException re) { 
      throw re.unwrapRemoteException(AccessControlException.class,  
                                     NSQuotaExceededException.class,  
                                     DSQuotaExceededException.class); 
    } 
  }
1233421
def get_src_or_dst_prompt(mode):
    
    _words = {"read": "from", "write": "to"}
    # print(os.getcwd())
    prompt = "Where would you like to {} your file(s) {}?\n" \
             "1. Desktop ({})\n" \
             "2. Downloads ({})\n" \
             "3. Current ({})\n" \
             "4. Browse".format(mode, _words[mode],
                                  os.path.expanduser('~/Desktop'),
                                    os.path.expanduser('~/Downloads'),
                                    os.getcwd())
    return prompt
750408
def copy_tree(src, dst, symlinks=False, ignore=[]):
    
    names = os.listdir(src)

    if not os.path.exists(dst):
        os.makedirs(dst)
    errors = []
    for name in names:
        if name in ignore:
            continue
        srcname = os.path.join(src, name)
        dstname = os.path.join(dst, name)
        try:
            if symlinks and os.path.islink(srcname):
                linkto = os.readlink(srcname)
                os.symlink(linkto, dstname)
            elif os.path.isdir(srcname):
                copy_tree(srcname, dstname, symlinks, ignore)
            else:
                copy_file(srcname, dstname)
        except (IOError, os.error) as exc:
            errors.append((srcname, dstname, str(exc)))
        except CTError as exc:
            errors.extend(exc.errors)
    if errors:
        raise CTError(errors)
448004
def download_from_url(src_url, dst_dir):
    
    dst_path = ""
    if "MD982181" not in src_url:
        dsn = input("Please enter the dataset name for this file (Name.Location.Year) : ")
        dst_path = os.path.join(dst_dir, dsn + ".lpd")
        try:
            print("downloading file from url...")
            urllib.request.urlretrieve(src_url, dst_path)
        except Exception as e:
            print("Error: unable to download from url: {}".format(e))
    else:
        print("Error: That file cannot be download due to server restrictions")
    return dst_path
46586
def cp(src, dst, overwrite=False):
    

    if not isinstance(src, list):
        src = [src]

    dst = os.path.expanduser(dst)
    dst_folder = os.path.isdir(dst)

    if len(src) > 1 and not dst_folder:
        raise OSError("Cannot copy multiple item to same file")

    for item in src:
        source = os.path.expanduser(item)
        destination = (dst if not dst_folder else
                       os.path.join(dst, os.path.basename(source)))
        if not overwrite and os.path.exists(destination):
            _logger.warning("Not replacing {0} with {1}, overwrite not enabled"
                            "".format(destination, source))
            continue

        shutil.copy(source, destination)
1299620
def copy_labels(src, dst):
    
    labels = src.__dict__.get('_labels')
    if labels is None:
        return
    dst.__dict__['_labels'] = labels.copy()