mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 06:09:39 +08:00
30 lines
508 B
Go
30 lines
508 B
Go
package fileutils2
|
|
|
|
import (
|
|
"os/exec"
|
|
"regexp"
|
|
"yunion.io/x/log"
|
|
)
|
|
|
|
const (
|
|
blkidTypePattern = `TYPE="(?P<type>\w+)"`
|
|
)
|
|
|
|
var (
|
|
blkidTypeRegexp = regexp.MustCompile(blkidTypePattern)
|
|
)
|
|
|
|
func GetBlkidType(filepath string) string {
|
|
cmd := exec.Command("blkid", filepath)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
log.Errorf("blkid fail %s %s", filepath, err)
|
|
return ""
|
|
}
|
|
matches := blkidTypeRegexp.FindStringSubmatch(string(out))
|
|
if len(matches) > 1 {
|
|
return matches[1]
|
|
}
|
|
return ""
|
|
}
|