Skip to content

Commit 05aa179

Browse files
authored
on livesync delete empty folders on exit (#821)
* on livesync delete empty folders on exit * add comment in code * added comment
1 parent 694fa48 commit 05aa179

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

build-artifacts/project-template-gradle/src/debug/java/com/tns/NativeScriptSyncService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,21 @@ private void deleteRemovedFiles(File sourceDir, String sourceRootAbsolutePath, S
268268
if (files != null) {
269269
for (int i = 0; i < files.length; i++) {
270270
File file = files[i];
271+
String targetFilePath = file.getAbsolutePath().replace(sourceRootAbsolutePath, targetRootAbsolutePath);
272+
File targetFile = new File(targetFilePath);
271273
if (file.isFile()) {
272274
if (logger.isEnabled()) {
273275
logger.write("Syncing removed file: " + file.getAbsolutePath().toString());
274276
}
275277

276-
String targetFilePath = file.getAbsolutePath().replace(sourceRootAbsolutePath, targetRootAbsolutePath);
277-
File targetFile = new File(targetFilePath);
278278
targetFile.delete();
279279
} else {
280280
deleteRemovedFiles(file, sourceRootAbsolutePath, targetRootAbsolutePath);
281+
282+
// this is done so empty folders, if any, are deleted after we're don deleting files.
283+
if (targetFile.listFiles().length == 0) {
284+
targetFile.delete();
285+
}
281286
}
282287
}
283288
}

test-app/app/src/main/java/com/tns/NativeScriptSyncService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,21 @@ private void deleteRemovedFiles(File sourceDir, String sourceRootAbsolutePath, S
268268
if (files != null) {
269269
for (int i = 0; i < files.length; i++) {
270270
File file = files[i];
271+
String targetFilePath = file.getAbsolutePath().replace(sourceRootAbsolutePath, targetRootAbsolutePath);
272+
File targetFile = new File(targetFilePath);
271273
if (file.isFile()) {
272274
if (logger.isEnabled()) {
273275
logger.write("Syncing removed file: " + file.getAbsolutePath().toString());
274276
}
275277

276-
String targetFilePath = file.getAbsolutePath().replace(sourceRootAbsolutePath, targetRootAbsolutePath);
277-
File targetFile = new File(targetFilePath);
278278
targetFile.delete();
279279
} else {
280280
deleteRemovedFiles(file, sourceRootAbsolutePath, targetRootAbsolutePath);
281+
282+
// this is done so empty folders, if any, are deleted after we're don deleting files.
283+
if (targetFile.listFiles().length == 0) {
284+
targetFile.delete();
285+
}
281286
}
282287
}
283288
}

0 commit comments

Comments
 (0)