blob: eb761e6a7cc60dd4a35e8165326653de9008fa8f [file] [log] [blame] [edit]
// Copyright 2022 The Centipede Authors.
//
// 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
//
// https://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.
// Implementation of the function from remote_file.h that don't directly depend
// a specific file system.
#include "./common/remote_file.h"
#include <string>
#include <string_view>
#include "absl/base/nullability.h"
#include "absl/log/check.h"
#include "./common/defs.h"
#include "./common/logging.h"
namespace centipede {
void RemoteFileAppend(absl::Nonnull<RemoteFile *> f,
const std::string &contents) {
ByteArray contents_ba{contents.cbegin(), contents.cend()};
RemoteFileAppend(f, contents_ba);
}
void RemoteFileRead(absl::Nonnull<RemoteFile *> f, std::string &contents) {
ByteArray contents_ba;
RemoteFileRead(f, contents_ba);
contents.assign(contents_ba.cbegin(), contents_ba.cend());
}
void RemoteFileSetContents(std::string_view path, const ByteArray &contents) {
auto *file = RemoteFileOpen(path, "w");
CHECK(file != nullptr) << VV(path);
RemoteFileAppend(file, contents);
RemoteFileClose(file);
}
void RemoteFileSetContents(std::string_view path, const std::string &contents) {
auto *file = RemoteFileOpen(path, "w");
CHECK(file != nullptr) << VV(path);
RemoteFileAppend(file, contents);
RemoteFileClose(file);
}
void RemoteFileGetContents(std::string_view path, ByteArray &contents) {
auto *file = RemoteFileOpen(path, "r");
CHECK(file != nullptr) << VV(path);
RemoteFileRead(file, contents);
RemoteFileClose(file);
}
void RemoteFileGetContents(std::string_view path, std::string &contents) {
auto *file = RemoteFileOpen(path, "r");
CHECK(file != nullptr) << VV(path);
RemoteFileRead(file, contents);
RemoteFileClose(file);
}
} // namespace centipede