fusefrontend_reverse: collapse getFileType

This commit is contained in:
Jakob Unterwurzacher 2020-08-01 20:28:06 +02:00
parent 1867fdaef4
commit dd3d8c100b

View File

@ -115,44 +115,31 @@ const (
typeRegular fileType = iota
// A DirIV (gocryptfs.diriv) file
typeDiriv
// A .name file for a file with a long name
// A gocryptfs.longname.*.name file for a file with a long name
typeName
// The config file
// The config file gocryptfs.conf
typeConfig
)
// getFileType returns the type of file. Only the name is checked
// getFileType returns the type of file (one of the fileType constants above).
func (rfs *ReverseFS) getFileType(cPath string) fileType {
if rfs.isDirIV(cPath) {
if !rfs.args.PlaintextNames {
cName := filepath.Base(cPath)
// Is it a gocryptfs.diriv file?
if cName == nametransform.DirIVFilename {
return typeDiriv
}
if rfs.isNameFile(cPath) {
// Is it a gocryptfs.longname.*.name file?
if t := nametransform.NameType(cName); t == nametransform.LongNameFilename {
return typeName
}
}
if rfs.isTranslatedConfig(cPath) {
return typeConfig
}
return typeRegular
}
// isDirIV determines if the path points to a gocryptfs.diriv file
func (rfs *ReverseFS) isDirIV(relPath string) bool {
if rfs.args.PlaintextNames {
return false
}
return filepath.Base(relPath) == nametransform.DirIVFilename
}
// isNameFile determines if the path points to a gocryptfs.longname.*.name
// file
func (rfs *ReverseFS) isNameFile(relPath string) bool {
if rfs.args.PlaintextNames {
return false
}
fileType := nametransform.NameType(filepath.Base(relPath))
return fileType == nametransform.LongNameFilename
}
// isTranslatedConfig returns true if the default config file name is in use
// and the ciphertext path is "gocryptfs.conf".
// "gocryptfs.conf" then maps to ".gocryptfs.reverse.conf" in the plaintext