Skip to content

Commit

Permalink
En route to #7, #8, #9; debugging is not completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgets committed Feb 15, 2018
1 parent 4d28a39 commit 00e66bb
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 23 deletions.
51 changes: 31 additions & 20 deletions src/MyArchive.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MyArchive {
private Boolean containsArchives;
private File archiveSource;
private ArrayList<String> archiveContents;
private HashMap<String, Boolean> internalArchives;
private ArrayList<MyArchive> internalArchives;

Set<PosixFilePermission> perms =
PosixFilePermissions.fromString("rwx------");
Expand All @@ -39,6 +39,7 @@ public MyArchive(String fn) throws Exception {
this.unrollPath = null;
this.arcFileName = fn;
this.archiveSource = new File(fn);
this.containsArchives = null;

if (!archiveSource.isFile()) {
throw new Exception("Invalid archive source: " + fn);
Expand All @@ -62,6 +63,10 @@ public File getArchiveSource() {
return this.archiveSource;
}

public ArrayList<MyArchive> getInternalArchives() {
return internalArchives;
}

//methods
private ArchiveInputStream getArchiveInputStream() throws Exception {
InputStream fis = new BufferedInputStream(
Expand All @@ -84,25 +89,8 @@ public HashMap<String, Boolean> getEntryHash() throws Exception {
ArchiveInputStream ais = getArchiveInputStream();

try {
setUnrollPath();
} catch (Exception ex) {
ais.close();
throw new Exception("Issue creating temp dir: " + ex.toString());
}

try {
//Boolean hit = false;

while ((entry = ais.getNextEntry()) != null) {
/*for (String ext : Util.flagExtensions) {
if (entry.getName().toLowerCase().endsWith(ext)) {
hit = true;
break;
}
}*/
archiveContents.add(entry.getName());
/*entryData.put(entry.getName(), hit);
hit = false;*/
}
} catch (Exception ex) {
ais.close();
Expand All @@ -115,14 +103,19 @@ public HashMap<String, Boolean> getEntryHash() throws Exception {
return entryData;
}

public HashMap<String, Boolean> unroll() throws Exception {
public HashMap<String, Boolean> unroll(Boolean keepGoing) throws Exception {
HashMap<String, Boolean> entryData = new HashMap<String, Boolean>();
ArchiveEntry entry;
File currentFile, parentFile;

ArchiveInputStream ais = getArchiveInputStream();

setUnrollPath();
try {
setUnrollPath();
} catch (Exception ex) {
ais.close();
throw new Exception("Issue creating temp dir: " + ex.toString());
}

if (RAS.VERBOSE) {
System.out.println("Attempting to expand " + arcFileName +
Expand Down Expand Up @@ -154,6 +147,24 @@ public HashMap<String, Boolean> unroll() throws Exception {
}
}

if (keepGoing) {
for (String fName : entryData.keySet()) {
if (entryData.get(fName)) {
internalArchives.add(new MyArchive(fName));
}

if (!internalArchives.isEmpty()) {
this.containsArchives = true;
} else {
this.containsArchives = false;
}
}

Util.unrollNextArchives(this);
}



return entryData;
}
}
16 changes: 14 additions & 2 deletions src/RAS.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class RAS {
public static final boolean VERBOSE = true;
public static final boolean UNROLL_FIRST = false;
public static final boolean USING_LISTER = false;
public static final boolean KEEP_GOING = true;

/**
* @param args
Expand Down Expand Up @@ -51,14 +52,25 @@ public static void main(String[] args) {

displayEntryData(directory);
} else if (args.length == 2 && args[0].equals("-x")) {
MyArchive archive = null;
//expand contents
try {
MyArchive archive = new MyArchive(args[1]);
archive.unroll();
archive = new MyArchive(args[1]);
archive.unroll(KEEP_GOING); //this will be set by user arg l8r
} catch (Exception ex) {
System.err.println("MyArchive Error: " +
ex.getMessage());
}

if (archive.getContainsArchives()) {
try {
Util.unrollNextArchives(archive);
} catch (Exception ex) {
System.err.println("Util.unrollNextArchives() error: " +
ex.getMessage());
return;
}
}
} else {
//we're not there yet
System.out.println("Not supported yet . . .");
Expand Down
18 changes: 17 additions & 1 deletion src/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,26 @@ public static HashMap<String, Boolean> findEmbedded(ArrayList<String> contents)
return contentFlags;
}

public static Boolean checkDriveSpace(MyArchive archive, String partitionPath) {
public static Boolean adequateDriveSpace(MyArchive archive, String partitionPath) {
File tmpDir = new File(System.getProperty("java.io.tmpdir"));

return (tmpDir.getFreeSpace() >=
(archive.getArchiveSource().length() * decompressionFactor));
}

public static void unrollNextArchives(MyArchive currentArchive) throws Exception {
//ArrayList<MyArchive> nextArchives = new ArrayList<MyArchive>();

for (MyArchive ouah : currentArchive.getInternalArchives()) {
try {
ouah.unroll(RAS.KEEP_GOING);
} catch (Exception ex) {
throw new Exception("Oh shit: " + ex.getMessage());
}
}
}

public static void cleanUpMess(MyArchive wipeExpandedArchive) {

}
}

0 comments on commit 00e66bb

Please sign in to comment.