diff --git a/akshat12000/goorm.manifest b/akshat12000/goorm.manifest new file mode 100644 index 0000000..24bb1b7 --- /dev/null +++ b/akshat12000/goorm.manifest @@ -0,0 +1 @@ +{"storage":"container","type":"cpp","detailedtype":"cpp","author":"56737367_bp9gf_github","name":"TenDaysOfCode","description":"","date":"2020/10/3 4:22:45","plugins":{"goorm.plugin.cpp":[{"plugin.cpp.compiler_type":"g++","plugin.cpp.main":"main","plugin.cpp.source_path":"src/","plugin.cpp.makefile_path":"make","plugin.cpp.build_path":"bin/","plugin.cpp.build_option":"-g -std=c++17","plugin.cpp.makefile_option":"false","plugin.cpp.run_option":""}]},"is_user_plugin":false,"author_email":"ab.19u10704@btech.nitdgp.ac.in","author_name":"akshat12000","ignore_patterns":[],"project_domain":[{"id":"56737367_bp9gf_github","url":"tendaysofcode-fchch.run-ap-south1.goorm.io","port":"80"}],"visibility":1} \ No newline at end of file diff --git a/akshat12000/makefile b/akshat12000/makefile new file mode 100644 index 0000000..0400ab0 --- /dev/null +++ b/akshat12000/makefile @@ -0,0 +1,23 @@ + CXX := g++ +CXX_FLAGS := -std=c++17 -ggdb + +BIN := bin +SRC := src +INCLUDE := +LIB := lib +LIBRARIES := +EXECUTABLE := main + +all: $(BIN)/$(EXECUTABLE) + +run: clean all + @echo "run called" + ./$(BIN)/$(EXECUTABLE) +$(BIN)/$(EXECUTABLE): $(SRC)/*.cpp + + $(CXX) $(CXX_FLAGS) -I$(INCLUDE) -L$(LIB) $^ -o $ ~/imperium/$(BIN)/$(EXECUTABLE) $(LIBRARIES) -lssl -lcrypto -lstdc++fs + + +clean: + @echo "clean called" + @rm -rf -d ~/imperium/$(BIN)/* \ No newline at end of file diff --git a/akshat12000/readme.md b/akshat12000/readme.md new file mode 100644 index 0000000..f88183c --- /dev/null +++ b/akshat12000/readme.md @@ -0,0 +1,3 @@ +# Project Imperium (akshat12000) + +This is repository for submissions of project Imperium from Akshat Bhatnagar. diff --git a/akshat12000/scripts/build.sh b/akshat12000/scripts/build.sh new file mode 100644 index 0000000..643a04a --- /dev/null +++ b/akshat12000/scripts/build.sh @@ -0,0 +1,16 @@ +#!/bin/bash +sudo apt-get update +sudo apt-get install openssl -y +sudo apt-get install libssl-dev -y +mkdir -p ~/imperium/bin +cp imperium.sh ~/imperium +cd .. +make +cd ~/imperium/bin || echo "error" +chmod +x main +cd .. +if grep -q "source $PWD/imperium.sh" "$PWD/../.bashrc" ; then + echo 'already installed bash source'; +else + echo "source $PWD/imperium.sh" >> ~/.bashrc; +fi diff --git a/akshat12000/scripts/imperium.sh b/akshat12000/scripts/imperium.sh new file mode 100644 index 0000000..e1589fb --- /dev/null +++ b/akshat12000/scripts/imperium.sh @@ -0,0 +1,8 @@ +#!/bin/bash +function imperium(){ +DIR=$PWD +export dir=$DIR +cd ~/imperium/bin || echo "Error" +./main "$@" +cd "$DIR" || echo "Error" +} diff --git a/akshat12000/src/main.cpp b/akshat12000/src/main.cpp new file mode 100644 index 0000000..b807a1e --- /dev/null +++ b/akshat12000/src/main.cpp @@ -0,0 +1,535 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#define pb push_back +using namespace std; +namespace fs=std::experimental::filesystem; +namespace fsnew=std::filesystem; +string root; +void init(string &path){ + struct stat buffer; + if(stat((path+"/.imperium").c_str(),&buffer)==0){ + cout<<"Repository has been already initialized\n"; return; + } + + string ignorePath=path+"/.imperiumignore"; + ofstream ignore(ignorePath.c_str()); + ignore<<".gitignore\n.imperium/\n.git\n.imperiumignore\n.node_modules\n"; + ignore.close(); + path+="/.imperium"; + if(mkdir(path.c_str(),0777)!=0) {cout<<"_ERROR_\n"; return;} + + string commitLog=path+"/commit.log"; + ofstream commit(commitLog.c_str()); + commit.close(); + + string addLog=path+"/add.log"; + ofstream add(addLog.c_str()); + add.close(); + + string conflictLog=path+"/conflict.log"; + ofstream conflict(conflictLog.c_str()); + conflict<<"False\n"; + conflict.close(); + + cout<<"Initialized an empty repository\n"; +} +void addtoCache(string addPath,char type){ + struct stat buffer; + if(stat((root+"/.imperium/.add").c_str(),&buffer)) { + if(mkdir((root+"/.imperium/.add").c_str(),0777)) {cout<<"Error could not create cache folder\n"; return;} + } + if(type=='d'){ + string filename=addPath.substr(root.length()); + string filerel=root+"/.imperium/.add"+filename; + struct stat buffer3; + if(stat(filerel.c_str(),&buffer3)!=0) + fsnew::create_directories(filerel); + } + else if(type=='f'){ + string filename=addPath.substr(root.length()); + string filerel=root+"/.imperium/.add" + filename.substr(0,filename.find_last_of("/")); + struct stat buffer2; + if(stat(filerel.c_str(),&buffer2)!=0) + fsnew::create_directories(filerel); + fsnew::copy_file(addPath,root+"/.imperium/.add"+filename,fsnew::copy_options::overwrite_existing); + } +} +bool ignoreFolder(string addPath,vector &ignoreDir) +{ + for(auto dir:ignoreDir){ + if(dir.find(addPath)!=string::npos) return true; + if(addPath.find(dir)!=string::npos) return true; + } + return false; +} +bool toBeIgnored(string addPath,int onlyImperiumIgnore=0) +{ + ifstream addFIle, ignoreFile; + string file_or_dir; + vector ignorefilenames; + vector> addedFileNames; + vector ignoreDir; + ignoreFile.open(root+"/.imperiumignore"); + addFIle.open(root+"/.imperium/add.log"); + if(ignoreFile.is_open()){ + while(!ignoreFile.eof()){ + getline(ignoreFile,file_or_dir); + if(file_or_dir.back()=='/') ignoreDir.push_back(root+"/"+file_or_dir); + else ignorefilenames.push_back(root+"/"+file_or_dir); + } + } + ignoreFile.close(); + if(onlyImperiumIgnore==0){ + if(addFIle.is_open()){ + while(!addFIle.eof()){ + getline(addFIle,file_or_dir); + int len=file_or_dir.length(); + if(len>4){ + addedFileNames.pb({file_or_dir.substr(1,len-4),file_or_dir.back()}); + } + } + } + addFIle.close(); + for(auto fileEntry:addedFileNames){ + if(addPath.compare(fileEntry.first)==0){ + addtoCache(addPath,fileEntry.second); + cout<<"Updated "<HEAD\n"; + + string line; + while(getline(readCommitlog,line)) + { + if(line.find(" -->HEAD")!=string::npos) + { + writeCommitlog<staged; + vectortype; + vectornotStaged; + ifstream readCommitlog; + string stagedPath; + + readCommitlog.open(root+"/.imperium/commit.log"); + getline(readCommitlog,headHash); + + headHash=headHash.substr(0,40); + readCommitlog.close(); + + if(stat((root+"/.imperium/.add").c_str(),&buf)==0) + { + readAddlog.open(root+"/.imperium/add.log"); + + while(getline(readAddlog,line)) + { + stagedPath=line.substr(root.length()+1,line.length()-root.length()-4); + if(stat((root+"/.imperium/.add/"+stagedPath).c_str(),&buf)==0) + { + if((stat((root+"/.imperium/.commit"+headHash+stagedPath).c_str(),&buf)!=0)||stat((root+"/.imperium/.commit").c_str(),&buf)!=0) + { + type.push_back("created: "); + staged.push_back(stagedPath); + } + if(find(staged.begin(),staged.end(),stagedPath)==staged.end()) + { + notStaged.push_back("deleted: "+stagedPath); + } + else{ + if(compareFiles(root+stagedPath,root+"/.imperium/.add/"+stagedPath)) + { + notStaged.push_back("modified: "+stagedPath); + } + } + } + } + } + readAddlog.close(); + struct stat s; + if(stat((root+"/.imperium/.commit").c_str(),&buf)==0) + { + for(auto &p: fs::recursive_directory_iterator(root)) + { + if(stat(p.path().c_str(),&s)==0) + { + string rootPath=p.path(); + + if(toBeIgnored(p.path().c_str(),1)) + continue; + + string commitPath=root+"/.imperium/.commit"+headHash+rootPath.substr(root.length()); + + if(stat(commitPath.c_str(),&s)!=0 && (find(staged.begin(),staged.end(),rootPath.substr(root.length()))==staged.end())) + { + for(int i=0;i