Fixed filename size handling

This commit is contained in:
Uwe Seimet 2021-08-23 14:19:12 +02:00
parent 07c08945db
commit 3c40e6a188
2 changed files with 9 additions and 6 deletions

View File

@ -257,10 +257,12 @@ void GetImageFile(PbImageFile *image_file, const string& filename)
{
image_file->set_name(filename);
if (!filename.empty()) {
image_file->set_read_only(access(filename.c_str(), W_OK));
string f = filename[0] == '/' ? filename : default_image_folder + "/" + filename;
image_file->set_read_only(access(f.c_str(), W_OK));
struct stat st;
stat(filename.c_str(), &st);
stat(f.c_str(), &st);
image_file->set_size(st.st_size);
}
}

View File

@ -192,15 +192,16 @@ void CommandServerInfo(const string& hostname, int port)
cout << " No image files available in the default folder" << endl;
}
else {
list<string> sorted_files;
list<PbImageFile> sorted_files;
for (int i = 0; i < serverInfo.available_image_files_size(); i++) {
sorted_files.push_back(serverInfo.available_image_files(i).name());
sorted_files.push_back(serverInfo.available_image_files(i));
}
sorted_files.sort();
sorted_files.sort([](const PbImageFile& a, const PbImageFile& b) { return a.name() < b.name(); });
cout << "Image files available in the default folder:" << endl;
for (auto it = sorted_files.begin(); it != sorted_files.end(); ++it) {
cout << " " << *it << endl;
cout << " " << (*it).name() << " (" << (*it).size() << " bytes)" << ((*it).read_only() ? ", read only": "")
<< endl;
}
}
}