MCPcopy
hub / github.com/Velocidex/velociraptor / checkFile

Function checkFile

tools/survey/storage.go:123–158  ·  view source on GitHub ↗
(write_path string)

Source from the content-addressed store, hash-verified

121}
122
123func checkFile(write_path string) error {
124 dirname := filepath.Dir(write_path)
125 st, err := os.Lstat(dirname)
126 if err != nil {
127 if os.IsNotExist(err) {
128 return fmt.Errorf("Directory %v does not exist", dirname)
129 }
130 if os.IsPermission(err) {
131 return fmt.Errorf("Directory %v is not accessibile: %w",
132 dirname, err)
133 }
134
135 return fmt.Errorf("Directory %v is not valid", dirname)
136 }
137
138 if !st.IsDir() {
139 return fmt.Errorf("Directory %v is not a valid directory", dirname)
140 }
141
142 st, err = os.Lstat(write_path)
143 if err != nil {
144 if os.IsNotExist(err) {
145 return fileDoesNotExist
146 }
147
148 if os.IsPermission(err) {
149 return fmt.Errorf("Unable to create file: %w", err)
150 }
151 }
152
153 if st.IsDir() {
154 return fmt.Errorf("Path %v is a directory", write_path)
155 }
156
157 return nil
158}

Callers 1

StoreServerConfigFunction · 0.85

Calls 4

DirMethod · 0.65
LstatMethod · 0.65
IsDirMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected