mirror of
https://gitea.home.endeavr.de/Marcel/Tarstats-pp.git
synced 2025-12-10 00:39:01 +01:00
Prototyping:
- Opening a GNU Tar file via comand line argument - Parse itemname, itemtype and itemsize in bytes of first item in Tar archive - Print those to stdout.
This commit is contained in:
Binary file not shown.
@@ -9,3 +9,21 @@
|
|||||||
434 493 1644015948036364707 Tarstats__ f7cfe02335deb4e2
|
434 493 1644015948036364707 Tarstats__ f7cfe02335deb4e2
|
||||||
0 427 1644016477076983653 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8
|
0 427 1644016477076983653 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8
|
||||||
427 493 1644016477140983588 Tarstats__ f7cfe02335deb4e2
|
427 493 1644016477140983588 Tarstats__ f7cfe02335deb4e2
|
||||||
|
0 538 1644147062140655424 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8
|
||||||
|
538 602 1644147062204655425 Tarstats__ f7cfe02335deb4e2
|
||||||
|
1 615 1644148034020627712 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8
|
||||||
|
616 678 1644148034080630244 Tarstats__ f7cfe02335deb4e2
|
||||||
|
1 629 1644148143958504291 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8
|
||||||
|
629 692 1644148144022504164 Tarstats__ f7cfe02335deb4e2
|
||||||
|
1 622 1644148949596376843 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8
|
||||||
|
622 687 1644148949660376224 Tarstats__ f7cfe02335deb4e2
|
||||||
|
0 681 1644149569239272180 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8
|
||||||
|
681 748 1644149569303272155 Tarstats__ f7cfe02335deb4e2
|
||||||
|
1 638 1644149631123177220 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8
|
||||||
|
639 705 1644149631187177051 Tarstats__ f7cfe02335deb4e2
|
||||||
|
1 619 1644149687714975354 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8
|
||||||
|
619 683 1644149687778975068 Tarstats__ f7cfe02335deb4e2
|
||||||
|
1 635 1644149729622762080 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8
|
||||||
|
636 703 1644149729686761716 Tarstats__ f7cfe02335deb4e2
|
||||||
|
1 622 1644149788698378263 CMakeFiles/Tarstats__.dir/main.cpp.o bda4693f6e34dbc8
|
||||||
|
622 689 1644149788762377798 Tarstats__ f7cfe02335deb4e2
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,3 @@
|
|||||||
Start testing: Feb 05 00:14 CET
|
Start testing: Feb 06 13:16 CET
|
||||||
----------------------------------------------------------
|
----------------------------------------------------------
|
||||||
End testing: Feb 05 00:14 CET
|
End testing: Feb 06 13:16 CET
|
||||||
|
|||||||
79
main.cpp
79
main.cpp
@@ -1,26 +1,75 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::ifstream datei("test.tar", std::ios::binary);
|
|
||||||
if(!datei)
|
|
||||||
std::cout << "Fehler beim Oeffnen der Datei" << std::endl;
|
|
||||||
|
|
||||||
int headersize = 512;
|
|
||||||
char* headbuffer = new char[headersize];
|
|
||||||
|
|
||||||
datei.read(headbuffer, headersize);
|
|
||||||
std::string filename{};
|
int main(int argc, char** argv) {
|
||||||
for (int i = 0; i <= 99; i++)
|
|
||||||
{
|
// Trivial check for arguments. Errorprone and has to be changed.
|
||||||
if (headbuffer[i] != '\0')
|
if (argc < 2) {
|
||||||
filename.push_back(headbuffer[i]);
|
std::cout << "Please enter filename" << std::endl;
|
||||||
|
return 9;
|
||||||
}
|
}
|
||||||
std::cout << filename << std::endl;
|
// Getting name from argument lists on startup. Trivial and errorprone. Placeholder for now.
|
||||||
|
std::string archiveFilename(argv[1]);
|
||||||
|
|
||||||
std::string filename2(&headbuffer[0], 100);
|
//Open tar File.
|
||||||
std::cout << filename2 << std::endl;
|
std::ifstream datei(archiveFilename, std::ios::binary);
|
||||||
|
if(!datei)
|
||||||
|
std::cout << "Error opening file" << std::endl;
|
||||||
|
|
||||||
|
// Tar spec is working with continous 512 byte size blocks. Header is 512 bytes.
|
||||||
|
int headersize = 512;
|
||||||
|
|
||||||
|
//Read header of first item in tar archive
|
||||||
|
char* headbuffer = new char[headersize];
|
||||||
|
datei.read(headbuffer, headersize);
|
||||||
|
|
||||||
|
// Read name of the next item
|
||||||
|
std::string itemname(&headbuffer[0], 100);
|
||||||
|
std::erase(itemname, '\0');
|
||||||
|
|
||||||
|
// Read type of item
|
||||||
|
std::string itemtype{};
|
||||||
|
switch (headbuffer[156]){
|
||||||
|
case '0': case '\0':
|
||||||
|
itemtype = "FILE";
|
||||||
|
break;
|
||||||
|
case '1':
|
||||||
|
itemtype = "HARDLINK";
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
itemtype = "SYMLINK";
|
||||||
|
break;
|
||||||
|
case '5':
|
||||||
|
itemtype = "DIRECTORY";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
itemtype = "OTHER";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Read size of the next file
|
||||||
|
long double filesize{};
|
||||||
|
int power = 10;
|
||||||
|
std::string asciifilesize(&headbuffer[124], 11);
|
||||||
|
for (auto i : asciifilesize) {
|
||||||
|
int value = i - '0';
|
||||||
|
filesize += value * std::pow(8,power);
|
||||||
|
power--;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Printing to stdout
|
||||||
|
std::cout << itemname << std::endl;
|
||||||
|
std::cout << itemtype << std::endl;
|
||||||
|
std::cout << filesize << " Bytes" << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user