| 216 | } |
| 217 | |
| 218 | bool FileStat(FileInfo &info, const char *path, bool follow_links) { |
| 219 | struct stat st; |
| 220 | if (follow_links) { |
| 221 | if (stat(path, &st) < 0) |
| 222 | return false; |
| 223 | } else { |
| 224 | if (lstat(path, &st) < 0) |
| 225 | return false; |
| 226 | } |
| 227 | memset(&info, 0, sizeof(info)); |
| 228 | if (S_ISDIR(st.st_mode)) { |
| 229 | info.is_dir = true; |
| 230 | } else if (S_ISREG(st.st_mode)) { |
| 231 | info.is_file = true; |
| 232 | } else if (S_ISLNK(st.st_mode)) { |
| 233 | info.is_link = true; |
| 234 | } else { |
| 235 | info.is_other = true; |
| 236 | } |
| 237 | info.atime = st.st_atime; |
| 238 | info.mtime = st.st_mtime; |
| 239 | info.ctime = st.st_ctime; |
| 240 | info.size = st.st_size; |
| 241 | return true; |
| 242 | } |
| 243 | |
| 244 | bool FileStat(FileInfo &info, Str *path, bool follow_links) { |
| 245 | return FileStat(info, path->c_str(), follow_links); |