]> 127.0.0.1 Git - part/.git/commitdiff
Improve
authorqydysky <32743305+qydysky@users.noreply.github.com>
Thu, 9 Feb 2023 16:09:26 +0000 (00:09 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Thu, 9 Feb 2023 16:09:26 +0000 (00:09 +0800)
file/FileWR.go

index b9f3ae79c229f5276ee2eeb96571a8a59646feb9..7bfe0d24795d1a7bd44ad48d7fd542980003270f 100644 (file)
@@ -277,6 +277,25 @@ func (t *File) IsExist() bool {
        return true
 }
 
+func (t *File) IsDir() bool {
+       if len(t.Config.FilePath) > 4096 {
+               panic(ErrFilePathTooLong)
+       }
+
+       info, err := os.Stat(t.Config.FilePath)
+       if err != nil {
+               if errors.Is(err, os.ErrNotExist) {
+                       return false
+               } else {
+                       if !strings.Contains(err.Error(), "file name too long") {
+                               panic(ErrFilePathTooLong)
+                       }
+                       return false
+               }
+       }
+       return info.IsDir()
+}
+
 func (t *File) File() *os.File {
        t.getRWCloser()
        return t.file