Skip to content

Commit 7070b2f

Browse files
authored
Merge pull request #743 from NativeScript/pete/delete-temp-sync-dir
Force delete temporary livesync dir after syncing .xml or .css files
2 parents 30bf433 + ac74dc7 commit 7070b2f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ public void run() {
128128
int length = input.readInt();
129129
input.readFully(new byte[length]); // ignore the payload
130130
executePartialSync(context, syncDir);
131+
// delete temporary /sync dir after syncing .xml/.css resources
132+
deleteRecursive(syncDir);
131133
executeRemovedSync(context, removedSyncDir);
134+
// delete temporary /removedsync dir after removing files from the project
135+
deleteRecursive(removedSyncDir);
132136

133137
runtime.runScript(new File(NativeScriptSyncService.this.context.getFilesDir(), "internal/livesync.js"));
134138
try {
@@ -157,7 +161,11 @@ private void deleteRecursive(File fileOrDirectory) {
157161
}
158162
}
159163

160-
fileOrDirectory.delete();
164+
boolean success = fileOrDirectory.delete();
165+
166+
if (!success && fileOrDirectory.isDirectory()) {
167+
android.util.Log.d("Sync", "Failed to delete temp sync directory: " + fileOrDirectory.getAbsolutePath());
168+
}
161169
}
162170

163171
public static boolean isSyncEnabled(Context context) {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ public void run() {
128128
int length = input.readInt();
129129
input.readFully(new byte[length]); // ignore the payload
130130
executePartialSync(context, syncDir);
131+
// delete temporary /sync dir after syncing .xml/.css resources
132+
deleteRecursive(syncDir);
131133
executeRemovedSync(context, removedSyncDir);
134+
// delete temporary /removedsync dir after removing files from the project
135+
deleteRecursive(removedSyncDir);
132136

133137
runtime.runScript(new File(NativeScriptSyncService.this.context.getFilesDir(), "internal/livesync.js"));
134138
try {
@@ -157,7 +161,11 @@ private void deleteRecursive(File fileOrDirectory) {
157161
}
158162
}
159163

160-
fileOrDirectory.delete();
164+
boolean success = fileOrDirectory.delete();
165+
166+
if (!success && fileOrDirectory.isDirectory()) {
167+
android.util.Log.d("Sync", "Failed to delete temp sync directory: " + fileOrDirectory.getAbsolutePath());
168+
}
161169
}
162170

163171
public static boolean isSyncEnabled(Context context) {

0 commit comments

Comments
 (0)