MCPcopy Create free account
hub / github.com/Recordscript/recordscript / read_dir_recursive

Function read_dir_recursive

libs/hbb_common/src/fs.rs:125–182  ·  view source on GitHub ↗
(
    path: &PathBuf,
    prefix: &Path,
    include_hidden: bool,
)

Source from the content-addressed store, hash-verified

123}
124
125fn read_dir_recursive(
126 path: &PathBuf,
127 prefix: &Path,
128 include_hidden: bool,
129) -> ResultType<Vec<FileEntry>> {
130 let mut files = Vec::new();
131 if path.is_dir() {
132 // to-do: symbol link handling, cp the link rather than the content
133 // to-do: file mode, for unix
134 let fd = read_dir(path, include_hidden)?;
135 for entry in fd.entries.iter() {
136 match entry.entry_type.enum_value() {
137 Ok(FileType::File) => {
138 let mut entry = entry.clone();
139 entry.name = get_string(&prefix.join(entry.name));
140 files.push(entry);
141 }
142 Ok(FileType::Dir) => {
143 if let Ok(mut tmp) = read_dir_recursive(
144 &path.join(&entry.name),
145 &prefix.join(&entry.name),
146 include_hidden,
147 ) {
148 for entry in tmp.drain(0..) {
149 files.push(entry);
150 }
151 }
152 }
153 _ => {}
154 }
155 }
156 Ok(files)
157 } else if path.is_file() {
158 let (size, modified_time) = if let Ok(meta) = std::fs::metadata(path) {
159 (
160 meta.len(),
161 meta.modified()
162 .map(|x| {
163 x.duration_since(std::time::SystemTime::UNIX_EPOCH)
164 .map(|x| x.as_secs())
165 .unwrap_or(0)
166 })
167 .unwrap_or(0),
168 )
169 } else {
170 (0, 0)
171 };
172 files.push(FileEntry {
173 entry_type: FileType::File.into(),
174 size,
175 modified_time,
176 ..Default::default()
177 });
178 Ok(files)
179 } else {
180 bail!("Not exists");
181 }
182}

Callers 1

get_recursive_filesFunction · 0.85

Calls 5

read_dirFunction · 0.85
get_stringFunction · 0.85
iterMethod · 0.80
joinMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected