Helper for updatePath and updatePaths functions. Queries stats for source and target
and ensures target directory exists before copying a file.
429004
function updatePathInternal(sourcePath, targetPath, options, log) {
    var rootDir = (options && options.rootDir) || "";
    var targetFullPath = path.join(rootDir, targetPath);
    var targetStats = fs.existsSync(targetFullPath) ? fs.statSync(targetFullPath) : null;
    var sourceStats = null;

    if (sourcePath) {
        // A non-null source path was specified. It should exist.
        var sourceFullPath = path.join(rootDir, sourcePath);
        if (!fs.existsSync(sourceFullPath)) {
            throw new Error("Source path does not exist: " + sourcePath);
        }

        sourceStats = fs.statSync(sourceFullPath);

        // Create the target's parent directory if it doesn't exist.
        var parentDir = path.dirname(targetFullPath);
        if (!fs.existsSync(parentDir)) {
            shell.mkdir("-p", parentDir);
        }
    }

    return updatePathWithStats(sourcePath, sourceStats, targetPath, targetStats, options, log);
}
252741
function(src, filepath) {
					/*
					return '// Source: ' + filepath + '\n' +
						src.replace(/##VERSION##/g, '##FOUND##');
					*/
					src = src.replace(/##ID##/g, options.id);
					src = src.replace(/##VERSION##/g, options.version);
					src = src.replace(/##CODEBASE##/g, options.extension.updateUrl);
					return src;
				}
279517
private void restoreInstanceDirectoryFromPath(Path source, String instanceRocksDBPath) throws IOException {

		FileSystem fileSystem = source.getFileSystem();

		final FileStatus[] fileStatuses = fileSystem.listStatus(source);

		if (fileStatuses == null) {
			throw new IOException("Cannot list file statues. Directory " + source + " does not exist.");
		}

		for (FileStatus fileStatus : fileStatuses) {
			final Path filePath = fileStatus.getPath();
			final String fileName = filePath.getName();
			File restoreFile = new File(source.getPath(), fileName);
			File targetFile = new File(instanceRocksDBPath, fileName);
			if (fileName.endsWith(SST_FILE_SUFFIX)) {
				// hardlink'ing the immutable sst-files.
				Files.createLink(targetFile.toPath(), restoreFile.toPath());
			} else {
				// true copy for all other files.
				Files.copy(restoreFile.toPath(), targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
			}
		}
	}
132515
private void updateQuotaForPath(String path) {
        Counts c = new Counts();
        getCounts(path, c);
        StatsTrack strack = new StatsTrack();
        strack.setBytes(c.bytes);
        strack.setCount(c.count);
        String statPath = Quotas.quotaZookeeper + path + "/" + Quotas.statNode;
        DataNode node = getNode(statPath);
        // it should exist
        if (node == null) {
            LOG.warn("Missing quota stat node " + statPath);
            return;
        }
        synchronized (node) {
            node.data = strack.toString().getBytes();
        }
    }
1053132
function statFile(filePath, callback) {
  fs.stat(filePath, function(err, stats) {

    // Resource does not exist
    if (err && (err.code === 'ENOENT' || err.code === 'ENOTDIR')) {
      const error = new Error('Resource does not exist');
      error.httpCode = 404;

      callback(error);

    // Not a file
    } else if (!stats.isFile()) {
      const error = new Error('Resource is not a file');
      error.httpCode = 400;

      callback(error);

    // Server error
    } else if (err) {
      const error = new Error('Server error');
      error.httpCode = 500;

      callback(error);

    // Success. Get the stats.
    } else {
      callback(null, stats);
    }
  });
}
1050598
function modifyStatsObject ( stats, path ) {
  stats.path = path;
  stats.basename = fs.basename(path);
  stats.dirname = fs.dirname(path);
  stats.extname = fs.extname(path);
  return stats;
}
525736
function copyFileIntoDirectory(srcPath, destPath) {
        return ensureDestinationDirectory(destPath).then(function () {
            return new Promise(function (resolve, reject) {
                fs.readFile(srcPath, 'utf8', function (err, contents) {
                    if (!err) {
                        resolve();
                    } else {
                        reject(err);
                    }
                    fs.outputFile(destPath + '/' + path.basename(srcPath), contents, function (err) {
                        if (!err) {
                            resolve();
                        } else {
                            reject(err);
                        }
                    });
                });
            });
        });
    }
940494
def file_needs_update?(filename: nil)
      # looking for something like: FastlaneRunnerAPIVersion [0.9.1]
      regex_to_use = API_VERSION_REGEX

      source = File.join(self.source_swift_code_file_folder_path, "/#{filename}")
      target = File.join(self.target_swift_code_file_folder_path, "/#{filename}")

      # target doesn't have the file yet, so ya, I'd say it needs to be updated
      return true unless File.exist?(target)

      source_file_content = File.read(source)
      target_file_content = File.read(target)

      bundled_version = source_file_content.match(regex_to_use)[1]
      target_version = target_file_content.match(regex_to_use)[1]
      file_versions_are_different = bundled_version != target_version

      UI.verbose("#{filename} FastlaneRunnerAPIVersion (bundled/target): #{bundled_version}/#{target_version}")
      files_are_different = source_file_content != target_file_content

      if files_are_different && !file_versions_are_different
        UI.verbose("File versions are the same, but the two files are not equal, so that's a problem, setting needs update to 'true'")
      end

      needs_update = file_versions_are_different || files_are_different

      return needs_update
    end
116688
def UpdateFrom(self, src):
    
    if not isinstance(src, PathInfo):
      raise TypeError("expected `%s` but got `%s`" % (PathInfo, type(src)))
    if self.path_type != src.path_type:
      raise ValueError(
          "src [%s] does not represent the same path type as self [%s]" %
          (src.path_type, self.path_type))
    if self.components != src.components:
      raise ValueError("src [%s] does not represent the same path as self [%s]"
                       % (src.components, self.components))

    if src.HasField("stat_entry"):
      self.stat_entry = src.stat_entry

    self.last_stat_entry_timestamp = max(self.last_stat_entry_timestamp,
                                         src.last_stat_entry_timestamp)
    self.directory = self.directory or src.directory
275413
function (dir_path) {
  return fs.statAsync(dir_path)
    .call('isDirectory')
    .then(function (isDirectory) {
      if (isDirectory) {
        return fs.readdirAsync(dir_path)
          .map(function (file_name) {
            var file_path = dir_path + '/' + file_name;
            return fs.statAsync(file_path)
              .then(function (stat) {
                return {
                  isDirectory: stat.isDirectory(),
                  file_path: file_path
                }
              })
          })
          .reduce(function (files, file_item) {
            if (file_item.isDirectory) {
              return getFilesByDir(file_item.file_path)
                .then(function (subDirFiles) {
                  return files.concat(subDirFiles)
                })
            }
            files.push(file_item.file_path);
            return files
          }, [])
      }
      throw new Error('Please input a valid directory!');
    })
}
935482
def update(target, path, value):
    
    names = path.split(".")
    names_length = len(names)
    node = target
    for index in range(names_length):
        name = names[index]
        if index == names_length - 1:
            last = True
        else:
            last = False
        if isinstance(node, dict):
            if last:
                node[name] = value
                return
            else:
                if not name in node:
                    node[name] = {}
                node = node[name]
        elif isinstance(node, list):
            name = int(name)
            listpad(node, name+1)
            if last:
                node[name] = value
                return
            else:
                node[name] = {}
                node = node[name]
        else:
            if last:
                setattr(node, name, value)
            else:
                setattr(node, name, {})
                node = getattr(node, name)
1041524
function isDirectory(filePath, callback) {
  try {
    fs.stat(filePath, function (err, data) {
      if (err) {
        callback(null, false);
      } else {
        callback(null, data.isDirectory());
      }
    });
  } catch (e) {
    callback(null, false);
  }
}
948362
function mergePathMaps(sourceMaps, targetMap, targetDir) {
    // Merge multiple source maps together, along with target path info.
    // Entries in later source maps override those in earlier source maps.
    // Target stats will be filled in below for targets that exist.
    var pathMap = {};
    sourceMaps.forEach(function (sourceMap) {
        Object.keys(sourceMap).forEach(function(sourceSubPath){
            var sourceEntry = sourceMap[sourceSubPath];
            pathMap[sourceSubPath] = {
                targetPath: path.join(targetDir, sourceSubPath),
                targetStats: null,
                sourcePath: path.join(sourceEntry.subDir, sourceSubPath),
                sourceStats: sourceEntry.stats
            };
        });
    });

    // Fill in target stats for targets that exist, and create entries
    // for targets that don't have any corresponding sources.
    Object.keys(targetMap).forEach(function(subPath){
        var entry = pathMap[subPath];
        if (entry) {
            entry.targetStats = targetMap[subPath].stats;
        } else {
            pathMap[subPath] = {
                targetPath: path.join(targetDir, subPath),
                targetStats: targetMap[subPath].stats,
                sourcePath: null,
                sourceStats: null
            };
        }
    });

    return pathMap;
}
1155802
def copyfile(self, target):
        
        shutil.copyfile(self.path, self._to_backend(target))
815677
function stat(path, callback) {
        appshell.fs.stat(path, function (err, stats) {
            if (err) {
                callback(_mapError(err));
            } else {
                var options = {
                    isFile: stats.isFile(),
                    mtime: stats.mtime,
                    size: stats.size,
                    realPath: stats.realPath,
                    hash: stats.mtime.getTime()
                };

                var fsStats = new FileSystemStats(options);

                callback(null, fsStats);
            }
        });
    }
700863
function (path) {
        var self = this;

        path = /^(.*?)\/?(\w+)?$/.exec(path);

        // Update path parts
        self.path = path[0];
        self.directory = path[1];
        self.file = path[2];

        // Rebuild source
        self.source = '';
        self.getURI();
      }
307096
async function fileExists(path) {
  try {
    const stats = await stat(path);
    return stats.isFile() ? true : false;
  } catch (err) {
    return false;
  }
}