Browse Source

IdentifyType.

Blallo 5 years ago
parent
commit
1650750fd0
1 changed files with 13 additions and 3 deletions
  1. 13 3
      sizer/main.go

+ 13 - 3
sizer/main.go

@@ -84,9 +84,19 @@ func (i *INode) Name() string {
 	return name
 }
 
-// IdentifyType classifies a file-like object in one of the FileTypes.
-func IdentifyType(path string) (int, error) {
-	return -1, ErrNotIdenfiedType
+// IdentifyType classifies a file-like object in one of the FileType.
+func IdentifyType(path string) (int, int64, error) {
+	f, err := os.Lstat(path)
+	if err != nil {
+		return -1, 0, err
+	}
+	switch mode := f.Mode(); {
+	case mode.IsDir():
+		return DirType, f.Size(), nil
+	case mode.IsRegular():
+		return FileType, f.Size(), nil
+	}
+	return -1, 0, ErrNotIdenfiedType
 }
 
 func ls(path string) ([]string, error) {