blob: 65ce0b8d4d12f3c51852bdea5e65bd5de81d1f52 [file] [log] [blame]
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package file
import (
"io"
"os"
"android.googlesource.com/platform/tools/gpu/framework/log"
)
// Mkdir creates the directory specified.
func Mkdir(dir Path) error {
if dir.IsEmpty() {
return nil
}
return os.MkdirAll(dir.value, os.ModePerm)
}
// Remove deletes the file.
func Remove(f Path) error {
return os.Remove(f.value)
}
// Copy copies src to dst, replacing any existing file at dst.
func Copy(ctx log.Context, dst Path, src Path) error {
ctx = ctx.V("Source", src).V("Destination", dst)
s, err := os.Open(src.value)
if err != nil {
return ctx.WrapError(err, "Opening source")
}
defer s.Close()
d, err := os.OpenFile(dst.System(), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, src.Info().Mode())
if err != nil {
return ctx.WrapError(err, "Creating destination")
}
defer d.Close()
if _, err = io.Copy(d, s); err != nil {
return ctx.WrapError(err, "Copying data")
}
return nil
}