-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathfe-ls.cc
More file actions
68 lines (57 loc) · 1.66 KB
/
Copy pathfe-ls.cc
File metadata and controls
68 lines (57 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "lib/globals.h"
#include "lib/flags.h"
#include "lib/fluxmap.h"
#include "lib/sector.h"
#include "lib/proto.h"
#include "lib/readerwriter.h"
#include "lib/decoders/decoders.h"
#include "lib/fluxsource/fluxsource.h"
#include "lib/imagereader/imagereader.h"
#include "fluxengine.h"
#include "lib/vfs/sectorinterface.h"
#include "lib/vfs/vfs.h"
#include "lib/utils.h"
#include "lib/usb/usb.h"
#include "src/fileutils.h"
#include <google/protobuf/text_format.h>
#include <fstream>
static FlagGroup flags({&fileFlags});
static StringFlag directory({"-p", "--path"}, "path to list", "");
static char fileTypeChar(FileType file_type)
{
switch (file_type)
{
case TYPE_FILE:
return ' ';
case TYPE_DIRECTORY:
return 'D';
default:
return '?';
}
}
int mainLs(int argc, const char* argv[])
{
if (argc == 1)
showProfiles("ls", formats);
flags.parseFlagsWithConfigFiles(argc, argv, formats);
auto usb = USB::create();
auto filesystem = Filesystem::createFilesystemFromConfig();
auto files = filesystem->list(Path(directory));
int maxlen = 0;
for (const auto& dirent : files)
maxlen = std::max(maxlen, (int)quote(dirent->filename).size());
uint32_t total = 0;
for (const auto& dirent : files)
{
fmt::print("{} {:{}} {:6} {:4} {}\n",
fileTypeChar(dirent->file_type),
quote(dirent->filename),
maxlen + 2,
dirent->length,
dirent->mode,
dirent->attributes[Filesystem::CTIME]);
total += dirent->length;
}
fmt::print("({} files, {} bytes)\n", files.size(), total);
return 0;
}