Decide whether a file/directory is too small to raid.
1980
public static boolean shouldRaid(Configuration conf, FileSystem srcFs, 
      FileStatus stat, Codec codec, List<FileStatus> lfs) throws IOException {
    Path p = stat.getPath();
    long blockNum = 0L;
    if (stat.isDir() != codec.isDirRaid) {
      return false;
    }
    
    if (tooNewForRaid(stat)) {
      return false;
    }
    
    blockNum = codec.isDirRaid ? 
        DirectoryStripeReader.getBlockNum(lfs) : numBlocks(stat);
    
    // if the file/directory has fewer than 2 blocks, then nothing to do
    if (blockNum <= RaidState.TOO_SMALL_NOT_RAID_NUM_BLOCKS) {
      return false;
    }
    
    return !raidedByOtherHighPriCodec(conf, stat, codec);
  }
480329
def valid_directory?(entry)
      File.directory?(source.join(entry)) && !IGNORE_DIR.include?(File.basename(entry))
    end
1023558
def detect(self, volume_system, vstype='detect'):
        """'"""
        volume = volume_system._make_single_subvolume(offset=0)
        is_directory = os.path.isdir(volume_system.parent.get_raw_path())

        if is_directory:
            filesize = _util.check_output_(['du', '-scDb', volume_system.parent.get_raw_path()]).strip()
            if filesize:
                volume.size = int(filesize.splitlines()[-1].split()[0])

        else:
            description = _util.check_output_(['file', '-sL', volume_system.parent.get_raw_path()]).strip()
            if description:
                # description is the part after the :, until the first comma
                volume.info['fsdescription'] = description.split(': ', 1)[1].split(',', 1)[0].strip()
                if 'size' in description:
                    volume.size = int(re.findall(r'size:? (\d+)', description)[0])
                else:
                    volume.size = os.path.getsize(volume_system.parent.get_raw_path())

        volume.flag = 'alloc'
        volume_system.volume_source = 'single'
        volume_system._assign_disktype_data(volume)
        yield volume
591870
def extend_is_dir(value, minimum=None, maximum=None):
    
    """

    if isinstance(value, list):
        return [is_dir(member)
                for member in validate.is_list(value, minimum, maximum)]

    else:
        return is_dir(value)
16886
function checkFileExists(filename, callback) {
  if (fs.exists !== undefined) {
    fs.exists(filename, callback);
  } else {
    fs.stat(filename, function (err) {
      callback(!err);
    });
  }
}
82805
def _file_recv(self, load):
        '''
        
        '''
        if any(key not in load for key in ('id', 'path', 'loc')):
            return False
        if not self.opts['file_recv'] or os.path.isabs(load['path']):
            return False
        if os.path.isabs(load['path']) or '../' in load['path']:
            # Can overwrite master files!!
            return False
        if not salt.utils.verify.valid_id(self.opts, load['id']):
            return False
        file_recv_max_size = 1024*1024 * self.opts['file_recv_max_size']

        if 'loc' in load and load['loc'] < 0:
            log.error('Invalid file pointer: load[loc] < 0')
            return False

        if load.get('size', 0) > file_recv_max_size:
            log.error(
                'Exceeding file_recv_max_size limit: %s',
                file_recv_max_size
            )
            return False

        if len(load['data']) + load.get('loc', 0) > file_recv_max_size:
            log.error(
                'Exceeding file_recv_max_size limit: %s',
                file_recv_max_size
            )
            return False
        # Normalize Windows paths
        normpath = load['path']
        if ':' in normpath:
            # make sure double backslashes are normalized
            normpath = normpath.replace('\\', '/')
            normpath = os.path.normpath(normpath)
        cpath = os.path.join(
            self.opts['cachedir'],
            'minions',
            load['id'],
            'files',
            normpath)
        cdir = os.path.dirname(cpath)
        if not os.path.isdir(cdir):
            try:
                os.makedirs(cdir)
            except os.error:
                pass
        if os.path.isfile(cpath) and load['loc'] != 0:
            mode = 'ab'
        else:
            mode = 'wb'
        with salt.utils.files.fopen(cpath, mode) as fp_:
            if load['loc']:
                fp_.seek(load['loc'])
            fp_.write(salt.utils.stringutils.to_str(load['data']))
        return True
723207
public static boolean isFileSizeUnderLimit(ByteSizeValue limit, long fileSizeAsBytes) {
        boolean result = true;
        if (limit != null) {
            // We check the file size to avoid indexing too big files
            ByteSizeValue fileSize = new ByteSizeValue(fileSizeAsBytes);
            int compare = fileSize.compareTo(limit);
            result = compare <= 0;
            logger.debug("Comparing file size [{}] with current limit [{}] -> {}", fileSize, limit,
                    result ? "under limit" : "above limit");
        }

        return result;
    }
1154376
function size(file) {
  if (!exists(file) || !isFile(file)) {
    return -1;
  } else {
    try {
      return _fileStats(file).size;
    } catch (e) {
      return -1;
    }
  }
}
823027
function verifySize(correctSize, filepath) {
    return calculateSize(filepath).then(size => {
        if (size !== correctSize) {
            throw new Error(`Incorrect file size: expected ${correctSize}, got ${size}`);
        }
        return true;
    });
}
821979
def should_skip(filename, config, path='/'):
    """"""
    for skip_path in config['skip']:
        if posixpath.abspath(posixpath.join(path, filename)) == posixpath.abspath(skip_path.replace('\\', '/')):
            return True

    position = os.path.split(filename)
    while position[1]:
        if position[1] in config['skip']:
            return True
        position = os.path.split(position[0])

    for glob in config['skip_glob']:
        if fnmatch.fnmatch(filename, glob):
            return True

    return False
1064959
def _ensure_directory_exists(self, directory):
        """"""
        if not os.path.lexists(directory):
            os.makedirs(directory)
        return directory
597167
def _verify_file_size(self):
        
        if self._file_size > PartSize.MAXIMUM_OBJECT_SIZE:
            self._status = TransferState.FAILED
            raise SbgError('File size = {}b. Maximum file size is {}b'.format(
                self._file_size, PartSize.MAXIMUM_OBJECT_SIZE)
            )
573988
def ensure_dir_exists(verify_dir):
    """"""
    if not os.path.exists(verify_dir):
        # Doesn't exist create dir
        os.makedirs(verify_dir)
    else:
        # Exists
        if not os.path.isdir(verify_dir):
            # Not a dir, raise an exception
            raise ValueError("{} is not a directory".format(verify_dir))
919431
def remote_file_size(self, remote_cmd="", remote_file=None):
        """"""
        return self._remote_file_size_unix(
            remote_cmd=remote_cmd, remote_file=remote_file
        )
466694
def files(self, paths, access=None, extensions=None, minsize=None):
        """"""
        self.failures = [path for path in paths if not
                         isvalid(path, access, extensions, 'file', minsize)]

        return not self.failures
526594
def is_valid_chunksize(chunk_size):
        """"""
        min_csize = current_app.config['FILES_REST_MULTIPART_CHUNKSIZE_MIN']
        max_csize = current_app.config['FILES_REST_MULTIPART_CHUNKSIZE_MAX']
        return chunk_size >= min_csize and chunk_size <= max_csize
846949
def is_dir(value):
    
    value = os.path.expanduser(value)
    value = os.path.expandvars(value)
    value = os.path.abspath(value)

    if os.path.exists(value):
        if os.path.isdir(value):
            if os.access(value, os.R_OK):
                return value

            else:
                err_message = ('{path}: Permission denied.'
                               ''.format(path=value)
                               )
                raise validate.VdtValueError(err_message)
        else:
            err_message = ('{value} is file.'
                           ''.format(value=value)
                           )
            raise validate.VdtTypeError(err_message)
    else:
        err_message = ('{path}: No such file or directory.'
                       ''.format(path=value)
                       )
        raise validate.VdtValueError(err_message)