1 | static bool dir2zip_recurse_honorDontBackupFiles_verbose; |
2 | |
3 | static int dir2zip_recurse_honorDontBackupFiles(File inDir, File zip) {
|
4 | ret dir2zip_recurse_honorDontBackupFiles(inDir, zip, ""); |
5 | } |
6 | |
7 | // automatically adds a dummy file (empty.txt) in case there are no files to zip |
8 | static int dir2zip_recurse_honorDontBackupFiles(File inDir, File zip, String outPrefix) ctex {
|
9 | mkdirsForFile(zip); |
10 | FileOutputStream fout = newFileOutputStream(zip); |
11 | ZipOutputStream outZip = new ZipOutputStream(fout); |
12 | try {
|
13 | int count = dir2zip_recurse_honorDontBackupFiles(inDir, outZip, outPrefix, 0); |
14 | if (count == 0) |
15 | zip_addDummyFile(outZip); |
16 | ret count; |
17 | } finally {
|
18 | outZip.close(); |
19 | } |
20 | } |
21 | |
22 | static int dir2zip_recurse_honorDontBackupFiles(File inDir, ZipOutputStream outZip) {
|
23 | ret dir2zip_recurse_honorDontBackupFiles(inDir, outZip, "", 0); |
24 | } |
25 | |
26 | static int dir2zip_recurse_honorDontBackupFiles(File inDir, ZipOutputStream outZip, String outPrefix, int level) ctex {
|
27 | if (++level >= 20) fail("woot? 20 levels in zip?");
|
28 | |
29 | Set<S> dontBackup = asSet(tlft(loadTextFile(newFile(inDir, standardNameOfDontBackupFile())))); |
30 | |
31 | new L<File> files; |
32 | for (File f : listFiles(inDir)) |
33 | if (!contains(dontBackup, f.getName())) |
34 | files.add(f); |
35 | |
36 | int n = 0; |
37 | sortFilesByName(files); |
38 | for (File f : files) {
|
39 | if (f.isDirectory()) {
|
40 | print("dir2zip_recurse_honorDontBackupFiles: Scanning " + f.getAbsolutePath());
|
41 | n += dir2zip_recurse_honorDontBackupFiles(f, outZip, outPrefix + f.getName() + "/", level); |
42 | } else {
|
43 | if (dir2zip_recurse_honorDontBackupFiles_verbose) print("Copying " + f.getName());
|
44 | outZip.putNextEntry(new ZipEntry(outPrefix + f.getName())); |
45 | InputStream fin = new FileInputStream(f); |
46 | copyStream(fin, outZip); |
47 | fin.close(); |
48 | ++n; |
49 | } |
50 | } |
51 | return n; |
52 | } |
Began life as a copy of #1002204
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1020482 |
| Snippet name: | dir2zip_recurse_honorDontBackupFiles |
| Eternal ID of this version: | #1020482/6 |
| Text MD5: | 3a8694ac5a0e072ebc3f1a9f06b4b965 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2019-03-04 11:36:26 |
| Source code size: | 1877 bytes / 52 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 681 / 725 |
| Version history: | 5 change(s) |
| Referenced in: | [show references] |