RmFile *rm_file_new(struct RmSession *session, const char *path, size_t path_len, RmStat *statp, RmLintType type, bool is_ppath, unsigned path_index) { RmCfg *cfg = session->cfg; RmOff actual_file_size = statp->st_size; RmOff start_seek = 0; /* Allow an actual file size of 0 for empty files */ if(actual_file_size != 0) { if(cfg->use_absolute_start_offset) { start_seek = cfg->skip_start_offset; if(cfg->skip_start_offset >= actual_file_size) { return NULL; } } else { start_seek = cfg->skip_start_factor * actual_file_size; if((int)(actual_file_size * cfg->skip_end_factor) == 0) { return NULL; } if(start_seek >= actual_file_size) { return NULL; } } } RmFile *self = g_slice_new0(RmFile); self->session = session; rm_file_set_path(self, (char *)path, path_len); self->inode = statp->st_ino; self->dev = statp->st_dev; self->mtime = statp->st_mtim.tv_sec; if(type == RM_LINT_TYPE_DUPE_CANDIDATE) { if(cfg->use_absolute_end_offset) { self->file_size = CLAMP(actual_file_size, 1, cfg->skip_end_offset); } else { self->file_size = actual_file_size * cfg->skip_end_factor; } } self->seek_offset = self->hash_offset = start_seek; self->lint_type = type; self->is_prefd = is_ppath; self->is_original = false; self->is_symlink = false; self->path_index = path_index; return self; }
static void rm_directory_to_file(RmTreeMerger *merger, const RmDirectory *self, RmFile *file) { memset(file, 0, sizeof(RmFile)); /* Need to set session first, since set_path expects that */ file->session = merger->session; rm_file_set_path(file, self->dirname); file->lint_type = RM_LINT_TYPE_DUPE_DIR_CANDIDATE; file->digest = self->digest; /* Set these to invalid for now */ file->mtime = self->metadata.dir_mtime; file->inode = self->metadata.dir_inode; file->dev = self->metadata.dir_dev; file->depth = rm_util_path_depth(self->dirname); /* Recursively calculate the file size */ file->file_size = rm_tm_calc_file_size(self); file->is_prefd = (self->prefd_files >= self->dupe_count); }
static RmFile *rm_directory_as_file(RmTreeMerger *merger, RmDirectory *self) { /* Masquerades a RmDirectory as RmFile for purpose of output */ RmFile *file = g_malloc0(sizeof(RmFile)); /* Need to set session first, since set_path expects that */ file->session = merger->session; rm_file_set_path(file, self->dirname, strlen(self->dirname)); file->lint_type = RM_LINT_TYPE_DUPE_DIR_CANDIDATE; file->digest = self->digest; /* Set these to invalid for now */ file->mtime = self->metadata.dir_mtime; file->inode = self->metadata.dir_inode; file->dev = self->metadata.dir_dev; /* Recursively calculate the file size */ file->file_size = rm_tm_calc_file_size(self); file->is_prefd = (self->prefd_files >= self->dupe_count); return file; }