mirror of
https://github.com/vbatts/go-mtree.git
synced 2025-10-04 12:31:00 +00:00
vis: refactored code to reflect using vis/unvis for file names
Added some more test cases for `vis`ing and `unvis`ing strings, and a test case that walks/checks a directory with filenames that require encoding. Had to change Path() to account for possible errors Unvis() could return. Refactored Vis()/Unvis() into go-mtree tar functionality as well. Signed-off-by: Stephen Chung <schung@redhat.com>
This commit is contained in:
parent
a63f83d94d
commit
773763fb87
12 changed files with 177 additions and 41 deletions
23
unvis.go
23
unvis.go
|
@ -1,15 +1,22 @@
|
|||
package mtree
|
||||
|
||||
// #include "vis.h"
|
||||
// #include <stdlib.h>
|
||||
import "C"
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func Unvis(str string) (string, error) {
|
||||
dst := new(C.char)
|
||||
ret := C.strunvis(dst, C.CString(str))
|
||||
if ret == 0 {
|
||||
return "", fmt.Errorf("failed to encode string")
|
||||
// Unvis is a wrapper for the C implementation of unvis, which decodes a string
|
||||
// that potentially has characters that are encoded with Vis
|
||||
func Unvis(src string) (string, error) {
|
||||
cDst, cSrc := C.CString(string(make([]byte, len(src)+1))), C.CString(src)
|
||||
defer C.free(unsafe.Pointer(cDst))
|
||||
defer C.free(unsafe.Pointer(cSrc))
|
||||
ret := C.strunvis(cDst, cSrc)
|
||||
if ret == -1 {
|
||||
return "", fmt.Errorf("failed to decode: %q", src)
|
||||
}
|
||||
|
||||
return C.GoString(dst), nil
|
||||
return C.GoString(cDst), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue