github.com/del680202/goofys@v0.19.1-0.20180727070818-6a609fafa266/internal/utils.go (about) 1 // Copyright 2015 - 2017 Ka-Hing Cheung 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package internal 16 17 import ( 18 "fmt" 19 "time" 20 "unicode" 21 22 "github.com/jacobsa/fuse" 23 ) 24 25 func MaxInt(a, b int) int { 26 if a > b { 27 return a 28 } else { 29 return b 30 } 31 } 32 33 func MinInt(a, b int) int { 34 if a < b { 35 return a 36 } else { 37 return b 38 } 39 } 40 41 func MaxUInt32(a, b uint32) uint32 { 42 if a > b { 43 return a 44 } else { 45 return b 46 } 47 } 48 49 func MinUInt32(a, b uint32) uint32 { 50 if a < b { 51 return a 52 } else { 53 return b 54 } 55 } 56 57 func MaxUInt64(a, b uint64) uint64 { 58 if a > b { 59 return a 60 } else { 61 return b 62 } 63 } 64 65 func MinUInt64(a, b uint64) uint64 { 66 if a < b { 67 return a 68 } else { 69 return b 70 } 71 } 72 73 func xattrEscape(value []byte) (s string) { 74 for _, c := range value { 75 if c == '%' { 76 s += "%25" 77 } else if unicode.IsPrint(rune(c)) { 78 s += string(c) 79 } else { 80 s += "%" + fmt.Sprintf("%02X", c) 81 } 82 } 83 84 return 85 } 86 87 func Dup(value []byte) []byte { 88 ret := make([]byte, len(value)) 89 copy(ret, value) 90 return ret 91 } 92 93 func TryUnmount(mountPoint string) (err error) { 94 for i := 0; i < 20; i++ { 95 err = fuse.Unmount(mountPoint) 96 if err != nil { 97 time.Sleep(time.Second) 98 } else { 99 break 100 } 101 } 102 return 103 }