fix •file.Type when file not present

This commit is contained in:
dzaima 2022-03-15 20:47:01 +02:00
parent 47c8c1e5de
commit eae7501d36
2 changed files with 7 additions and 2 deletions

View File

@ -676,7 +676,9 @@ B list_c1(B d, B x) {
}
B ftype_c1(B d, B x) {
return m_c32(path_type(path_rel(nfn_objU(d), x)));
char ty = path_type(path_rel(nfn_objU(d), x));
if (ty==0) thrM("•file.Type: Error while accessing file");
return m_c32(ty);
}
B fName_c1(B t, B x) {

View File

@ -224,8 +224,11 @@ B path_list(B path) {
char path_type(B path) {
char* p = toCStr(path);
struct stat path_stat;
stat(p, &path_stat);
int r = stat(p, &path_stat);
freeCStr(p);
dec(path);
if (r==-1) return 0;
i64 mode = path_stat.st_mode;
if (S_ISREG (mode)) return 'f';
if (S_ISDIR (mode)) return 'd';