exclude .DS_Store from generated zip files

This commit is contained in:
Grahame Grieve 2024-03-08 22:30:07 +11:00
parent 13dcebb3e4
commit 635ac6f109
1 changed files with 60 additions and 51 deletions

View File

@ -97,23 +97,27 @@ public class ZipGenerator {
File fd = new CSFile(actualDir);
String files[] = fd.list();
for (String f : files) {
if (!".DS_Store".equals(f)) {
if (new CSFile(Utilities.path(actualDir, f)).isDirectory())
addFolder(Utilities.path(actualDir, f), Utilities.pathURL(statedDir, f), omitIfExists);
else
addFileName(Utilities.pathURL(statedDir, f), Utilities.path(actualDir, f), omitIfExists);
}
}
}
public void addFolder(String actualDir, String statedDir, boolean omitIfExists, String noExt) throws IOException {
File fd = new CSFile(actualDir);
String files[] = fd.list();
for (String f : files) {
if (!".DS_Store".equals(f)) {
if (new CSFile(Utilities.path(actualDir, f)).isDirectory())
addFolder(Utilities.path(actualDir, f), Utilities.pathURL(statedDir, f), omitIfExists, noExt);
else if (noExt == null || !f.endsWith(noExt))
addFileName(Utilities.pathURL(statedDir, f), Utilities.path(actualDir, f), omitIfExists);
}
}
}
public void addFiles(String actualDir, String statedDir, String ext, String noExt) throws FileNotFoundException, IOException {
byte data[] = new byte[BUFFER];
@ -125,8 +129,10 @@ public class ZipGenerator {
System.out.println("no files found in "+f.getName());
} else {
for (int i = 0; i < files.length; i++) {
if ( new CSFile(actualDir + files[i]).isFile() && ((ext == null || files[i].endsWith(ext)) && (noExt == null || !files[i].endsWith(noExt)))) {
FileInputStream fi = new FileInputStream(actualDir + files[i]);
if (!".DS_Store".equals(files[i])) {
String fn = Utilities.path(actualDir, files[i]);
if ( new CSFile(fn).isFile() && ((ext == null || files[i].endsWith(ext)) && (noExt == null || !files[i].endsWith(noExt)))) {
FileInputStream fi = new FileInputStream(fn);
BufferedInputStream origin = new BufferedInputStream(fi, BUFFER);
ZipEntry entry = new ZipEntry(statedDir + files[i]);
names.add(statedDir + files[i]);
@ -140,6 +146,7 @@ public class ZipGenerator {
}
}
}
}
public void addFilesFiltered(String actualDir, String statedDir, String ext, String[] noExt) throws FileNotFoundException, IOException {
byte data[] = new byte[BUFFER];
@ -148,6 +155,7 @@ public class ZipGenerator {
String files[] = f.list();
for (int i = 0; i < files.length; i++) {
if (!".DS_Store".equals(files[i])) {
if ( new CSFile(actualDir + files[i]).isFile() && ((ext == null || files[i].endsWith(ext)))) {
boolean ok = true;
for (String n : noExt) {
@ -168,6 +176,7 @@ public class ZipGenerator {
}
}
}
}
public void addFileSource(String path, String cnt, boolean omitIfExists) throws IOException {
File tmp = Utilities.createTempFile("tmp", ".tmp");