File can't be found if "/" is in file name.
As in the title. I have numerous files that have the forward slash character in the title. It shows up when I use ls, however attempting to use stat or get on those files gives an error saying that the file doesn't exist.
I have tried escaping the forward slash, but even that hasn't worked.
EDIT: Anything with a ' also encounters an error, specifically "Error: EOF found when expecting closing quote". Escaping this one does work, but it'll need fixing in the autocomplete.
forward slash is problematic, it is used as a folder separator and cannot be escaped.
I... see what you mean. When it splits the path to navigate, it does a naive split (see rmapi/path.go)
The only solution I can see that would fix this would be to add an argument that would tell stat, rm, etc to ignore the forward slash. This would work for current folder operations, but not really anything deeper
An extension of this idea to allow for accessing deeper into the file structure is that spaces get used instead of forward slashes to delineate folders, and so each folder before the final folder/file gets entered as a separate argument into the shell command rather than splitting later on. Spaces already need to be escaped anyway if they are in a file/folder name to avoid creating a new argument, so this would solve the problem rather neatly.
This doesn't need to be the default behavior, so as mentioned before an argument could be passed that would use this alternative method.
Proof of concept for using arguments to separate folders and files rather than "/":
Rewriting statCmd in shell/stat.go
func statCmd(ctx *ShellCtxt) *ishell.Cmd {
return &ishell.Cmd{
Name: "stat",
Help: "fetch entry metadata",
Completer: createEntryCompleter(ctx),
Func: func(c *ishell.Context) {
if len(c.Args) == 0 {
c.Err(errors.New("missing source file"))
return
}
var node *model.Node
var err error
if (c.Args[0] == "-ap") && (len(c.Args) != 1) {
node, err = ctx.api.Filetree().NodeByArgPath(c.Args[1:], ctx.node)
} else {
srcName := c.Args[0]
node, err = ctx.api.Filetree().NodeByPath(srcName, ctx.node)
}
if err != nil {
c.Err(errors.New("file doesn't exist"))
return
}
jsn, err := json.MarshalIndent(node.Document, "", " ")
if err != nil {
c.Err(errors.New("can't serialize to json"))
return
}
c.Println(string(jsn))
},
}
}
Adding function to filetree/filetree.go
func (ctx *FileTreeCtx) NodeByArgPath(entries []string, current *model.Node) (*model.Node, error) {
if current == nil {
current = ctx.Root()
}
if len(entries) == 0 {
return current, nil
}
i := 0
if entries[i] == "" {
current = ctx.Root()
i++
}
for i < len(entries) {
if entries[i] == "" || entries[i] == "." {
i++
continue
}
if entries[i] == ".." {
if current.Parent == nil {
current = ctx.Root()
} else {
current = current.Parent
}
i++
continue
}
var err error
current, err = current.FindByName(entries[i])
if err != nil {
return nil, err
}
i++
}
return current, nil
}
This works and gave me the stats for a file with "/" in its name. It also works when working multiple folders deep.
Maybe we could use a combination of grave (`) and ampersand (&) symbols to indicate escapes?
Frankly this would reduce the number of incompatible files by a LOT. who uses & and ` in a file name anyway??