If the upstream doesn't have the file, get it from the alternate and store it in the upstream
495992
def _copy_across(self, rel_path, cb=None):
        """"""

        from . import copy_file_or_flo

        if not self.upstream.has(rel_path):

            if not self.alternate.has(rel_path):

                return None

            source = self.alternate.get_stream(rel_path)

            sink = self.upstream.put_stream(rel_path, metadata=source.meta)

            try:
                copy_file_or_flo(source, sink, cb=cb)
            except:
                self.upstream.remove(rel_path, propagate=True)
                raise

            source.close()
            sink.close()
524716
def file_exists(original_file):
    
    s3 = boto3.resource('s3')
    bucket_name, object_key = _parse_s3_file(original_file)
    bucket = s3.Bucket(bucket_name)
    bucket_iterator = bucket.objects.filter(Prefix=object_key)
    bucket_list = [x for x in bucket_iterator]
    logger.debug("Bucket List: {0}".format(", ".join([x.key for x in bucket_list])))
    logger.debug("bucket_list length: {0}".format(len(bucket_list)))
    return len(bucket_list) == 1
315679
def remote_file_exists(self, url):
        
        status = requests.head(url).status_code

        if status != 200:
            raise RemoteFileDoesntExist
654754
def load_from_unloaded(unloaded)
        unless file?(unloaded.filename)
          raise FileNotFound, "could not find file: #{unloaded.filename}"
        end

        path_to_split =
          if index_alias = unloaded.params[:index_alias]
            expand_from_root index_alias
          else
            unloaded.filename
          end

        load_path, logical_path = paths_split(config[:paths], path_to_split)

        unless load_path
          target = path_to_split
          target += " (index alias of #{unloaded.filename})" if unloaded.params[:index_alias]
          raise FileOutsidePaths, "#{target} is no longer under a load path: #{self.paths.join(', ')}"
        end

        extname, file_type = match_path_extname(logical_path, mime_exts)
        logical_path = logical_path.chomp(extname)
        name = logical_path

        if pipeline = unloaded.params[:pipeline]
          logical_path += ".#{pipeline}"
        end

        if type = unloaded.params[:type]
          logical_path += config[:mime_types][type][:extensions].first
        end

        if type != file_type && !config[:transformers][file_type][type]
          raise ConversionError, "could not convert #{file_type.inspect} to #{type.inspect}"
        end

        processors = processors_for(type, file_type, pipeline)

        processors_dep_uri = build_processors_uri(type, file_type, pipeline)
        dependencies = config[:dependencies] + [processors_dep_uri]

        # Read into memory and process if theres a processor pipeline
        if processors.any?
          result = call_processors(processors, {
            environment: self,
            cache: self.cache,
            uri: unloaded.uri,
            filename: unloaded.filename,
            load_path: load_path,
            name: name,
            content_type: type,
            metadata: {
              dependencies: dependencies
            }
          })
          validate_processor_result!(result)
          source = result.delete(:data)
          metadata = result
          metadata[:charset] = source.encoding.name.downcase unless metadata.key?(:charset)
          metadata[:digest]  = digest(self.version + source)
          metadata[:length]  = source.bytesize
        else
          dependencies << build_file_digest_uri(unloaded.filename)
          metadata = {
            digest: file_digest(unloaded.filename),
            length: self.stat(unloaded.filename).size,
            dependencies: dependencies
          }
        end

        asset = {
          uri: unloaded.uri,
          load_path: load_path,
          filename: unloaded.filename,
          name: name,
          logical_path: logical_path,
          content_type: type,
          source: source,
          metadata: metadata,
          dependencies_digest: DigestUtils.digest(resolve_dependencies(metadata[:dependencies]))
        }

        asset[:id]  = hexdigest(asset)
        asset[:uri] = build_asset_uri(unloaded.filename, unloaded.params.merge(id: asset[:id]))

        store_asset(asset, unloaded)
        asset
      end
665798
def files_exist(self):
        
        if not os.path.isfile(self.path + self.script):
            print("\nslpkg: Error: SlackBuild archive.tar.gz not found\n")
            raise SystemExit()
        for src in self.sources:
            if not os.path.isfile(self.path + src):
                print("\nslpkg: Error: Source file '{0}' not found\n".format(
                    src))
                raise SystemExit()
511226
function tryServeWithGzip() {
      fs.stat(gzippedFile, (err, stat) => {
        if (!err && stat.isFile()) {
          hasGzipId12(gzippedFile, (gzipErr, isGzip) => {
            if (!gzipErr && isGzip) {
              file = gzippedFile;
              serve(stat);
            } else {
              statFile();
            }
          });
        } else {
          statFile();
        }
      });
    }
1174298
function copyFile (src, dest) {
  return new Promise((resolve, reject) => {
    const read = fs.createReadStream(src);
    read.on('error', reject);
    const write = fs.createWriteStream(dest);
    write.on('error', reject);
    write.on('finish', resolve);
    read.pipe(write);
  })
}
1272893
def extant_file(x):
    
    if not os.path.exists(x):
        raise argparse.ArgumentError("{0} does not exist".format(x))
    return x
1020722
def _sync_extract(self, from_path, method, to_path):
    """"""
    to_path_tmp = '%s%s_%s' % (to_path, constants.INCOMPLETE_SUFFIX,
                               uuid.uuid4().hex)
    try:
      for path, handle in iter_archive(from_path, method):
        _copy(handle, path and os.path.join(to_path_tmp, path) or to_path_tmp)
    except BaseException as err:
      msg = 'Error while extracting %s to %s : %s' % (from_path, to_path, err)
      raise ExtractError(msg)
    # `tf.io.gfile.Rename(overwrite=True)` doesn't work for non empty
    # directories, so delete destination first, if it already exists.
    if tf.io.gfile.exists(to_path):
      tf.io.gfile.rmtree(to_path)
    tf.io.gfile.rename(to_path_tmp, to_path)
    self._pbar_path.update(1)
    return to_path
1309396
def get_file(self, *args, **kwargs):
        """"""
        return get_file(*args, **self._merge_overrides(**kwargs)).run()
1067252
def save_file(key, file_path, *refs):
    
    if not os.path.isfile(file_path):
        return error("Output '{}' set to a missing file: '{}'.".format(key, file_path))

    result = {key: {"file": file_path}}

    if refs:
        missing_refs = [
            ref for ref in refs if not (os.path.isfile(ref) or os.path.isdir(ref))
        ]
        if len(missing_refs) > 0:
            return error(
                "Output '{}' set to missing references: '{}'.".format(
                    key, ', '.join(missing_refs)
                )
            )
        result[key]['refs'] = refs

    return json.dumps(result)
468625
def rename_local_untracked(self):
        
        # Find what files have been added!
        new_upstream_files = self.find_upstream_changed('A')
        for f in new_upstream_files:
            if os.path.exists(f):
                # If there's a file extension, put the timestamp before that
                ts = datetime.datetime.now().strftime('__%Y%m%d%H%M%S')
                path_head, path_tail = os.path.split(f)
                path_tail = ts.join(os.path.splitext(path_tail))
                new_file_name = os.path.join(path_head, path_tail)
                os.rename(f, new_file_name)
                yield 'Renamed {} to {} to avoid conflict with upstream'.format(f, new_file_name)
300791
def fetch_file(self, in_path, out_path):
        vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
        '''  '''
        self.put_file(in_path, out_path)
937611
def combine(in_files, out_file, config):
    
    if not utils.file_exists(out_file):
        with file_transaction(config, out_file) as tx_out_file:
            with open(tx_out_file, "w") as out_handle:
                for in_file in in_files:
                    with open(in_file) as in_handle:
                        shutil.copyfileobj(in_handle, out_handle)
    return out_file
1345148
def download_file(client, bucket, remote_path, local_path, overwrite=False):
    """"""
    bucket = client.get_bucket(bucket)
    if (not overwrite) and os.path.isfile(local_path):
        raise OSError('File already exists!')
    with open(local_path, 'wb') as ofh:
        bucket.get_blob(remote_path).download_to_file(ofh)
18928
def _place_secondary_files(inp_tool, inp_binding=None):
    
    def _is_file(val):
        return (val == "File" or (isinstance(val, (list, tuple)) and
                                  ("File" in val or any(isinstance(x, dict) and _is_file(val)) for x in val)))
    secondary_files = inp_tool.pop("secondaryFiles", None)
    if secondary_files:
        key = []
        while (not _is_file(tz.get_in(key + ["type"], inp_tool))
               and not _is_file(tz.get_in(key + ["items"], inp_tool))
               and not _is_file(tz.get_in(key + ["items", "items"], inp_tool))):
            key.append("type")
        if tz.get_in(key, inp_tool):
            inp_tool["secondaryFiles"] = secondary_files
        elif inp_binding:
            nested_inp_binding = copy.deepcopy(inp_binding)
            nested_inp_binding["prefix"] = "ignore="
            nested_inp_binding["secondaryFiles"] = secondary_files
            inp_tool = tz.update_in(inp_tool, key, lambda x: nested_inp_binding)
    return inp_tool
1212373
function getAndWriteIncludedFile(file, includeDir) {
    return new Promise((resolve, reject) => {
        const fileName = file[0];
        const fileURL = file[1];

        const options = {
            url: fileURL,
            headers: {
                'User-Agent': 'request',
            },
        };

        request.get(options, (err, response, body) => {
            if (!err && response.statusCode === 200) {
                fs.writeFile(path.join(includeDir, fileName), body, (writeErr) => {
                    if (writeErr) {
                        resolve({
                            fileName,
                            successful: false,
                        });
                    } else {
                        resolve({
                            fileName,
                            successful: true,
                        });
                    }
                    return;
                });
            } else {
                resolve({
                    fileName,
                    successful: false,
                });
                return;
            }
        });
    });
}