43bool ArduinoMountImpl::isReadOnly()
const {
return read_only_; }
45Stat ArduinoMountImpl::stat(
const char* path)
const {
46 if (path ==
nullptr || path[0] !=
'/') {
47 return Stat(kInvalidPath);
49 if (!active_)
return Stat(kNotMounted);
50 if (!fs_.exists(path))
return Stat(kNotFound);
51 fs::File f = fs_.open(path,
"r");
52 if (!f)
return Stat(kNotFound);
53 return f.isDirectory() ? Stat(Stat::kDir, 0) : Stat(Stat::kFile, f.size());
56Status ArduinoMountImpl::remove(
const char* path) {
57 if (path ==
nullptr || path[0] !=
'/') {
63 fs::File f = fs_.open(path,
"r");
65 if (f.isDirectory())
return kNotFile;
70Status ArduinoMountImpl::rename(
const char* pathFrom,
const char* pathTo) {
72 if (fs_.rename(pathFrom, pathTo))
return kOk;
73 Stat src = stat(pathFrom);
77 Stat dst = stat(pathTo);
79 if (dst.status() != kNotFound)
return dst.status();
80 if (strncmp(pathFrom, pathTo, strlen(pathFrom)) == 0) {
84 std::unique_ptr<char[]> dup(
new char[strlen(pathTo) + 1]);
85 strcpy(dup.get(), pathTo);
86 char* last_slash = strrchr(dup.get(),
'/');
87 if (last_slash !=
nullptr) {
89 Stat dst_dir = stat(dup.get());
90 if (dst_dir.status() == kNotFound)
return kNotFound;
96Status ArduinoMountImpl::mkdir(
const char* path) {
97 if (path ==
nullptr || path[0] !=
'/') {
102 if (fs_.mkdir(path))
return kOk;
103 if (fs_.exists(path)) {
104 fs::File f = fs_.open(path,
"r");
111 Status status = CheckParentage(fs_, path);
112 if (status != kOk)
return status;
116Status ArduinoMountImpl::rmdir(
const char* path) {
117 if (path ==
nullptr || path[0] !=
'/') {
123 fs::File f = fs_.open(path,
"r");
126 if (fs_.rmdir(path))
return kOk;
130 child = f.openNextFile();
131 }
while (child && (strcmp(child.name(),
".") == 0 ||
132 strcmp(child.name(),
"..") == 0));
138std::unique_ptr<DirectoryImpl> ArduinoMountImpl::opendir(
139 std::shared_ptr<MountImpl> mount,
const char* path) {
141 fs::File f = fs_.open(path,
"r");
144 if (!fs_.exists(path)) {
150 return std::unique_ptr<DirectoryImpl>(
151 new ArduinoDirectoryImpl(std::move(mount), std::move(f), status));
154std::unique_ptr<MultipassInputStream> ArduinoMountImpl::fopen(
155 std::shared_ptr<MountImpl> mount,
const char* path) {
156 if (path ==
nullptr || path[0] !=
'/') {
160 fs::File f = fs_.open(path,
"r");
162 if (!fs_.exists(path)) {
168 if (f.isDirectory()) {
171 return std::unique_ptr<MultipassInputStream>(
172 new ArduinoFileInputStream(std::move(mount), std::move(f)));
175std::unique_ptr<OutputStream> ArduinoMountImpl::fopenForWrite(
176 std::shared_ptr<MountImpl> mount,
const char* path,
177 FileUpdatePolicy update_policy) {
178 if (path ==
nullptr || path[0] !=
'/') {
186 if (update_policy == kFailIfExists) {
187 if (fs_.exists(path)) {
188 f = fs_.open(path,
"r");
191 f = fs_.open(path,
"w");
195 f = fs_.open(path, update_policy == kTruncateIfExists ?
"w" :
"a");
196 if (!f && fs_.exists(path)) {
197 f = fs_.open(path,
"r");
198 if (f.isDirectory()) {
207 return std::unique_ptr<OutputStream>(
208 new ArduinoFileOutputStream(std::move(mount), std::move(f)));
211void ArduinoMountImpl::deactivate() { active_ =
false; }
std::unique_ptr< DirectoryImpl > DirectoryError(Status error)
roo::basic_string_view< CharT, Traits > basic_string_view
std::unique_ptr< OutputStream > OutputError(Status error)
std::unique_ptr< MultipassInputStream > InputError(Status error)