{"action":"created","comment":{"url":"https://api.github.com/repos/syncthing/syncthing-android/pulls/comments/185064202","pull_request_review_id":116381779,"id":185064202,"diff_hunk":"@@ -313,15 +322,25 @@ private void saveChanges() {\n             Log.w(TAG, \"Failed to save updated config. Cannot change the owner of the config file.\");\n             return;\n         }\n+\n+        Log.i(TAG, \"Writing updated config file\");\n+        File mConfigTempFile = Constants.getConfigTempFile(mContext);\n         try {\n-            Log.i(TAG, \"Writing updated config back to file\");\n             TransformerFactory transformerFactory = TransformerFactory.newInstance();\n             Transformer transformer = transformerFactory.newTransformer();\n             DOMSource domSource = new DOMSource(mConfig);\n-            StreamResult streamResult = new StreamResult(mConfigFile);\n+            StreamResult streamResult = new StreamResult(mConfigTempFile);\n             transformer.transform(domSource, streamResult);\n         } catch (TransformerException e) {\n-            Log.w(TAG, \"Failed to save updated config\", e);\n+            Log.w(TAG, \"Failed to save temporary config file\", e);\n+            return;\n+        }\n+        try {\n+            // Delete outdated config file and put temporary config file instead.\n+            mConfigFile.delete();\n+            mConfigTempFile.renameTo(mConfigFile);","path":"app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java","position":105,"original_position":105,"commit_id":"99849b907240debfb9df6945abe0e0cf66404870","original_commit_id":"cc81ab685c692896bfc2213eaa76a078969d64b2","user":{"login":"Catfriend1","id":16361913,"avatar_url":"https://avatars1.githubusercontent.com/u/16361913?v=4","gravatar_id":"","url":"https://api.github.com/users/Catfriend1","html_url":"https://github.com/Catfriend1","followers_url":"https://api.github.com/users/Catfriend1/followers","following_url":"https://api.github.com/users/Catfriend1/following{/other_user}","gists_url":"https://api.github.com/users/Catfriend1/gists{/gist_id}","starred_url":"https://api.github.com/users/Catfriend1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Catfriend1/subscriptions","organizations_url":"https://api.github.com/users/Catfriend1/orgs","repos_url":"https://api.github.com/users/Catfriend1/repos","events_url":"https://api.github.com/users/Catfriend1/events{/privacy}","received_events_url":"https://api.github.com/users/Catfriend1/received_events","type":"User","site_admin":false},"body":"hmm.. I'll better test this before as JavaDoc states it can be wrong. Link https://docs.oracle.com/javase/6/docs/api/java/io/File.html#renameTo%28java.io.File%29","created_at":"2018-04-30T18:10:36Z","updated_at":"2018-04-30T18:10:36Z","html_url":"https://github.com/syncthing/syncthing-android/pull/1074#discussion_r185064202","pull_request_url":"https://api.github.com/repos/syncthing/syncthing-android/pulls/1074","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/syncthing/syncthing-android/pulls/comments/185064202"},"html":{"href":"https://github.com/syncthing/syncthing-android/pull/1074#discussion_r185064202"},"pull_request":{"href":"https://api.github.com/repos/syncthing/syncthing-android/pulls/1074"}},"in_reply_to_id":185062433},"pull_request":{"url":"https://api.github.com/repos/syncthing/syncthing-android/pulls/1074","id":184871711,"html_url":"https://github.com/syncthing/syncthing-android/pull/1074","diff_url":"https://github.com/syncthing/syncthing-android/pull/1074.diff","patch_url":"https://github.com/syncthing/syncthing-android/pull/1074.patch","issue_url":"https://api.github.com/repos/syncthing/syncthing-android/issues/1074","number":1074,"state":"open","locked":false,"title":"fix config corruption on app upgrade or restore","user":{"login":"Catfriend1","id":16361913,"avatar_url":"https://avatars1.githubusercontent.com/u/16361913?v=4","gravatar_id":"","url":"https://api.github.com/users/Catfriend1","html_url":"https://github.com/Catfriend1","followers_url":"https://api.github.com/users/Catfriend1/followers","following_url":"https://api.github.com/users/Catfriend1/following{/other_user}","gists_url":"https://api.github.com/users/Catfriend1/gists{/gist_id}","starred_url":"https://api.github.com/users/Catfriend1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Catfriend1/subscriptions","organizations_url":"https://api.github.com/users/Catfriend1/orgs","repos_url":"https://api.github.com/users/Catfriend1/repos","events_url":"https://api.github.com/users/Catfriend1/events{/privacy}","received_events_url":"https://api.github.com/users/Catfriend1/received_events","type":"User","site_admin":false},"body":"Purpose\r\nThis PR should address the bug described in issue https://github.com/syncthing/syncthing-android/issues/1059 . ConfigXml/changeLocalDeviceName overrides all device names if the app has been upgraded or restored. Instead, it should only change the local device's name to build.model (phone model) as originally intended.\r\n\r\nImplementation\r\nI implemented a new function that reads the syncthing native binary log on first app launch after the keys got generated. Then, it extracts the local device ID and hands it over to changeLocalDeviceName which then ensures to only change the device name for the node having the correct device ID. If somehow the device ID cannot be retrieved, it won't do the first-app-launch rename of the local device for safety.\r\n\r\nTesting\r\nVerified working on my lg-h815 phone running Android 7.1.2.\r\n![image](https://user-images.githubusercontent.com/16361913/39414049-181e0a7e-4c33-11e8-808b-eaf5202ead4f.png)\r\n","created_at":"2018-04-30T03:00:57Z","updated_at":"2018-04-30T18:10:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7cba863fff25098bd9cb7b16b7bbc49de3a0b280","assignee":{"login":"Catfriend1","id":16361913,"avatar_url":"https://avatars1.githubusercontent.com/u/16361913?v=4","gravatar_id":"","url":"https://api.github.com/users/Catfriend1","html_url":"https://github.com/Catfriend1","followers_url":"https://api.github.com/users/Catfriend1/followers","following_url":"https://api.github.com/users/Catfriend1/following{/other_user}","gists_url":"https://api.github.com/users/Catfriend1/gists{/gist_id}","starred_url":"https://api.github.com/users/Catfriend1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Catfriend1/subscriptions","organizations_url":"https://api.github.com/users/Catfriend1/orgs","repos_url":"https://api.github.com/users/Catfriend1/repos","events_url":"https://api.github.com/users/Catfriend1/events{/privacy}","received_events_url":"https://api.github.com/users/Catfriend1/received_events","type":"User","site_admin":false},"assignees":[{"login":"Catfriend1","id":16361913,"avatar_url":"https://avatars1.githubusercontent.com/u/16361913?v=4","gravatar_id":"","url":"https://api.github.com/users/Catfriend1","html_url":"https://github.com/Catfriend1","followers_url":"https://api.github.com/users/Catfriend1/followers","following_url":"https://api.github.com/users/Catfriend1/following{/other_user}","gists_url":"https://api.github.com/users/Catfriend1/gists{/gist_id}","starred_url":"https://api.github.com/users/Catfriend1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Catfriend1/subscriptions","organizations_url":"https://api.github.com/users/Catfriend1/orgs","repos_url":"https://api.github.com/users/Catfriend1/repos","events_url":"https://api.github.com/users/Catfriend1/events{/privacy}","received_events_url":"https://api.github.com/users/Catfriend1/received_events","type":"User","site_admin":false}],"requested_reviewers":[{"login":"Nutomic","id":1044450,"avatar_url":"https://avatars1.githubusercontent.com/u/1044450?v=4","gravatar_id":"","url":"https://api.github.com/users/Nutomic","html_url":"https://github.com/Nutomic","followers_url":"https://api.github.com/users/Nutomic/followers","following_url":"https://api.github.com/users/Nutomic/following{/other_user}","gists_url":"https://api.github.com/users/Nutomic/gists{/gist_id}","starred_url":"https://api.github.com/users/Nutomic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nutomic/subscriptions","organizations_url":"https://api.github.com/users/Nutomic/orgs","repos_url":"https://api.github.com/users/Nutomic/repos","events_url":"https://api.github.com/users/Nutomic/events{/privacy}","received_events_url":"https://api.github.com/users/Nutomic/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":82100195,"url":"https://api.github.com/repos/syncthing/syncthing-android/labels/bug","name":"bug","color":"fc2929","default":true}],"milestone":null,"commits_url":"https://api.github.com/repos/syncthing/syncthing-android/pulls/1074/commits","review_comments_url":"https://api.github.com/repos/syncthing/syncthing-android/pulls/1074/comments","review_comment_url":"https://api.github.com/repos/syncthing/syncthing-android/pulls/comments{/number}","comments_url":"https://api.github.com/repos/syncthing/syncthing-android/issues/1074/comments","statuses_url":"https://api.github.com/repos/syncthing/syncthing-android/statuses/99849b907240debfb9df6945abe0e0cf66404870","head":{"label":"Catfriend1:fix-changeLocalDeviceName-rebase","ref":"fix-changeLocalDeviceName-rebase","sha":"99849b907240debfb9df6945abe0e0cf66404870","user":{"login":"Catfriend1","id":16361913,"avatar_url":"https://avatars1.githubusercontent.com/u/16361913?v=4","gravatar_id":"","url":"https://api.github.com/users/Catfriend1","html_url":"https://github.com/Catfriend1","followers_url":"https://api.github.com/users/Catfriend1/followers","following_url":"https://api.github.com/users/Catfriend1/following{/other_user}","gists_url":"https://api.github.com/users/Catfriend1/gists{/gist_id}","starred_url":"https://api.github.com/users/Catfriend1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Catfriend1/subscriptions","organizations_url":"https://api.github.com/users/Catfriend1/orgs","repos_url":"https://api.github.com/users/Catfriend1/repos","events_url":"https://api.github.com/users/Catfriend1/events{/privacy}","received_events_url":"https://api.github.com/users/Catfriend1/received_events","type":"User","site_admin":false},"repo":{"id":104175272,"name":"syncthing-android","full_name":"Catfriend1/syncthing-android","owner":{"login":"Catfriend1","id":16361913,"avatar_url":"https://avatars1.githubusercontent.com/u/16361913?v=4","gravatar_id":"","url":"https://api.github.com/users/Catfriend1","html_url":"https://github.com/Catfriend1","followers_url":"https://api.github.com/users/Catfriend1/followers","following_url":"https://api.github.com/users/Catfriend1/following{/other_user}","gists_url":"https://api.github.com/users/Catfriend1/gists{/gist_id}","starred_url":"https://api.github.com/users/Catfriend1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Catfriend1/subscriptions","organizations_url":"https://api.github.com/users/Catfriend1/orgs","repos_url":"https://api.github.com/users/Catfriend1/repos","events_url":"https://api.github.com/users/Catfriend1/events{/privacy}","received_events_url":"https://api.github.com/users/Catfriend1/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Catfriend1/syncthing-android","description":"Wrapper of syncthing for Android.","fork":true,"url":"https://api.github.com/repos/Catfriend1/syncthing-android","forks_url":"https://api.github.com/repos/Catfriend1/syncthing-android/forks","keys_url":"https://api.github.com/repos/Catfriend1/syncthing-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Catfriend1/syncthing-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Catfriend1/syncthing-android/teams","hooks_url":"https://api.github.com/repos/Catfriend1/syncthing-android/hooks","issue_events_url":"https://api.github.com/repos/Catfriend1/syncthing-android/issues/events{/number}","events_url":"https://api.github.com/repos/Catfriend1/syncthing-android/events","assignees_url":"https://api.github.com/repos/Catfriend1/syncthing-android/assignees{/user}","branches_url":"https://api.github.com/repos/Catfriend1/syncthing-android/branches{/branch}","tags_url":"https://api.github.com/repos/Catfriend1/syncthing-android/tags","blobs_url":"https://api.github.com/repos/Catfriend1/syncthing-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Catfriend1/syncthing-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Catfriend1/syncthing-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/Catfriend1/syncthing-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Catfriend1/syncthing-android/statuses/{sha}","languages_url":"https://api.github.com/repos/Catfriend1/syncthing-android/languages","stargazers_url":"https://api.github.com/repos/Catfriend1/syncthing-android/stargazers","contributors_url":"https://api.github.com/repos/Catfriend1/syncthing-android/contributors","subscribers_url":"https://api.github.com/repos/Catfriend1/syncthing-android/subscribers","subscription_url":"https://api.github.com/repos/Catfriend1/syncthing-android/subscription","commits_url":"https://api.github.com/repos/Catfriend1/syncthing-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/Catfriend1/syncthing-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/Catfriend1/syncthing-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/Catfriend1/syncthing-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/Catfriend1/syncthing-android/contents/{+path}","compare_url":"https://api.github.com/repos/Catfriend1/syncthing-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Catfriend1/syncthing-android/merges","archive_url":"https://api.github.com/repos/Catfriend1/syncthing-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Catfriend1/syncthing-android/downloads","issues_url":"https://api.github.com/repos/Catfriend1/syncthing-android/issues{/number}","pulls_url":"https://api.github.com/repos/Catfriend1/syncthing-android/pulls{/number}","milestones_url":"https://api.github.com/repos/Catfriend1/syncthing-android/milestones{/number}","notifications_url":"https://api.github.com/repos/Catfriend1/syncthing-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Catfriend1/syncthing-android/labels{/name}","releases_url":"https://api.github.com/repos/Catfriend1/syncthing-android/releases{/id}","deployments_url":"https://api.github.com/repos/Catfriend1/syncthing-android/deployments","created_at":"2017-09-20T06:30:30Z","updated_at":"2018-04-30T14:43:49Z","pushed_at":"2018-04-30T18:08:29Z","git_url":"git://github.com/Catfriend1/syncthing-android.git","ssh_url":"git@github.com:Catfriend1/syncthing-android.git","clone_url":"https://github.com/Catfriend1/syncthing-android.git","svn_url":"https://github.com/Catfriend1/syncthing-android","homepage":"https://syncthing.net/","size":9413,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mpl-2.0","name":"Mozilla Public License 2.0","spdx_id":"MPL-2.0","url":"https://api.github.com/licenses/mpl-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"syncthing:master","ref":"master","sha":"22e03d65da2c8c3f8fa7973a89359ab1a956dea4","user":{"login":"syncthing","id":7628018,"avatar_url":"https://avatars0.githubusercontent.com/u/7628018?v=4","gravatar_id":"","url":"https://api.github.com/users/syncthing","html_url":"https://github.com/syncthing","followers_url":"https://api.github.com/users/syncthing/followers","following_url":"https://api.github.com/users/syncthing/following{/other_user}","gists_url":"https://api.github.com/users/syncthing/gists{/gist_id}","starred_url":"https://api.github.com/users/syncthing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syncthing/subscriptions","organizations_url":"https://api.github.com/users/syncthing/orgs","repos_url":"https://api.github.com/users/syncthing/repos","events_url":"https://api.github.com/users/syncthing/events{/privacy}","received_events_url":"https://api.github.com/users/syncthing/received_events","type":"Organization","site_admin":false},"repo":{"id":17089728,"name":"syncthing-android","full_name":"syncthing/syncthing-android","owner":{"login":"syncthing","id":7628018,"avatar_url":"https://avatars0.githubusercontent.com/u/7628018?v=4","gravatar_id":"","url":"https://api.github.com/users/syncthing","html_url":"https://github.com/syncthing","followers_url":"https://api.github.com/users/syncthing/followers","following_url":"https://api.github.com/users/syncthing/following{/other_user}","gists_url":"https://api.github.com/users/syncthing/gists{/gist_id}","starred_url":"https://api.github.com/users/syncthing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syncthing/subscriptions","organizations_url":"https://api.github.com/users/syncthing/orgs","repos_url":"https://api.github.com/users/syncthing/repos","events_url":"https://api.github.com/users/syncthing/events{/privacy}","received_events_url":"https://api.github.com/users/syncthing/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/syncthing/syncthing-android","description":"Wrapper of syncthing for Android.","fork":false,"url":"https://api.github.com/repos/syncthing/syncthing-android","forks_url":"https://api.github.com/repos/syncthing/syncthing-android/forks","keys_url":"https://api.github.com/repos/syncthing/syncthing-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/syncthing/syncthing-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/syncthing/syncthing-android/teams","hooks_url":"https://api.github.com/repos/syncthing/syncthing-android/hooks","issue_events_url":"https://api.github.com/repos/syncthing/syncthing-android/issues/events{/number}","events_url":"https://api.github.com/repos/syncthing/syncthing-android/events","assignees_url":"https://api.github.com/repos/syncthing/syncthing-android/assignees{/user}","branches_url":"https://api.github.com/repos/syncthing/syncthing-android/branches{/branch}","tags_url":"https://api.github.com/repos/syncthing/syncthing-android/tags","blobs_url":"https://api.github.com/repos/syncthing/syncthing-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/syncthing/syncthing-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/syncthing/syncthing-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/syncthing/syncthing-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/syncthing/syncthing-android/statuses/{sha}","languages_url":"https://api.github.com/repos/syncthing/syncthing-android/languages","stargazers_url":"https://api.github.com/repos/syncthing/syncthing-android/stargazers","contributors_url":"https://api.github.com/repos/syncthing/syncthing-android/contributors","subscribers_url":"https://api.github.com/repos/syncthing/syncthing-android/subscribers","subscription_url":"https://api.github.com/repos/syncthing/syncthing-android/subscription","commits_url":"https://api.github.com/repos/syncthing/syncthing-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/syncthing/syncthing-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/syncthing/syncthing-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/syncthing/syncthing-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/syncthing/syncthing-android/contents/{+path}","compare_url":"https://api.github.com/repos/syncthing/syncthing-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/syncthing/syncthing-android/merges","archive_url":"https://api.github.com/repos/syncthing/syncthing-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/syncthing/syncthing-android/downloads","issues_url":"https://api.github.com/repos/syncthing/syncthing-android/issues{/number}","pulls_url":"https://api.github.com/repos/syncthing/syncthing-android/pulls{/number}","milestones_url":"https://api.github.com/repos/syncthing/syncthing-android/milestones{/number}","notifications_url":"https://api.github.com/repos/syncthing/syncthing-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/syncthing/syncthing-android/labels{/name}","releases_url":"https://api.github.com/repos/syncthing/syncthing-android/releases{/id}","deployments_url":"https://api.github.com/repos/syncthing/syncthing-android/deployments","created_at":"2014-02-22T17:15:19Z","updated_at":"2018-04-30T17:49:43Z","pushed_at":"2018-04-30T18:08:30Z","git_url":"git://github.com/syncthing/syncthing-android.git","ssh_url":"git@github.com:syncthing/syncthing-android.git","clone_url":"https://github.com/syncthing/syncthing-android.git","svn_url":"https://github.com/syncthing/syncthing-android","homepage":"https://syncthing.net/","size":9383,"stargazers_count":870,"watchers_count":870,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":157,"mirror_url":null,"archived":false,"open_issues_count":51,"license":{"key":"mpl-2.0","name":"Mozilla Public License 2.0","spdx_id":"MPL-2.0","url":"https://api.github.com/licenses/mpl-2.0"},"forks":157,"open_issues":51,"watchers":870,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/syncthing/syncthing-android/pulls/1074"},"html":{"href":"https://github.com/syncthing/syncthing-android/pull/1074"},"issue":{"href":"https://api.github.com/repos/syncthing/syncthing-android/issues/1074"},"comments":{"href":"https://api.github.com/repos/syncthing/syncthing-android/issues/1074/comments"},"review_comments":{"href":"https://api.github.com/repos/syncthing/syncthing-android/pulls/1074/comments"},"review_comment":{"href":"https://api.github.com/repos/syncthing/syncthing-android/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/syncthing/syncthing-android/pulls/1074/commits"},"statuses":{"href":"https://api.github.com/repos/syncthing/syncthing-android/statuses/99849b907240debfb9df6945abe0e0cf66404870"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"Catfriend1"}}