{"action":"created","comment":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/168338718","pull_request_review_id":96686488,"id":168338718,"diff_hunk":"@@ -119,167 +140,252 @@ bool BackupSupervisor::loadBackup(const QString& backupFile) {\n         const auto& assetHash = it.value().toString();\n \n         if (!AssetUtils::isValidHash(assetHash)) {\n-            qCritical() << \"Corrupted mapping in backup file\" << backupFile << \":\" << it.key();\n+            qCCritical(backup_supervisor) << \"Corrupted mapping in backup file\" << zip.getZipName() << \":\" << it.key();\n             backup.corruptedBackup = true;\n-            return false;\n+            _allBackupsLoadedSuccessfully = false;\n+            return;\n         }\n \n         backup.mappings[assetPath] = assetHash;\n         _assetsInBackups.insert(assetHash);\n     }\n \n+    return;\n+}\n+\n+void BackupSupervisor::createBackup(QuaZip& zip) {\n+    if (operationInProgress()) {\n+        qCWarning(backup_supervisor) << \"There is already an operation in progress.\";\n+        return;\n+    }\n+\n+    if (_lastMappingsRefresh == 0) {\n+        qCWarning(backup_supervisor) << \"Current mappings not yet loaded.\";\n+        return;\n+    }\n+\n+    static constexpr quint64 MAX_REFRESH_TIME = 15 * 60 * 1000 * 1000;\n+    if (usecTimestampNow() - _lastMappingsRefresh > MAX_REFRESH_TIME) {\n+        qCWarning(backup_supervisor) << \"Backing up asset mappings that appear old.\";\n+    }\n+\n+    AssetServerBackup backup;\n+    backup.filePath = zip.getZipName();\n+\n+    QJsonObject jsonObject;\n+    for (const auto& mapping : _currentMappings) {\n+        backup.mappings[mapping.first] = mapping.second;\n+        _assetsInBackups.insert(mapping.second);\n+        jsonObject.insert(mapping.first, mapping.second);\n+    }\n+    QJsonDocument document(jsonObject);\n+\n+    QuaZipFile zipFile { &zip };\n+    if (!zipFile.open(QIODevice::WriteOnly, QuaZipNewInfo(MAPPINGS_FILE))) {\n+        qCDebug(backup_supervisor) << \"testCreate(): outFile.open()\";\n+        return;\n+    }\n+    zipFile.write(document.toJson());\n+    zipFile.close();\n+    if (zipFile.getZipError() != UNZ_OK) {\n+        qCDebug(backup_supervisor) << \"testCreate(): outFile.close(): \" << zipFile.getZipError();\n+        return;\n+    }\n     _backups.push_back(backup);\n-    return true;\n }\n \n-void BackupSupervisor::backupAssetServer() {\n-    if (backupInProgress() || restoreInProgress()) {\n-        qWarning() << \"There is already a backup/restore in progress.\";\n+void BackupSupervisor::recoverBackup(QuaZip& zip) {\n+    if (operationInProgress()) {\n+        qCWarning(backup_supervisor) << \"There is already a backup/restore in progress.\";\n         return;\n     }\n \n-    auto assetClient = DependencyManager::get<AssetClient>();\n-    auto request = assetClient->createGetAllMappingsRequest();\n+    if (_lastMappingsRefresh == 0) {\n+        qCWarning(backup_supervisor) << \"Current mappings not yet loaded.\";\n+        return;\n+    }\n \n-    connect(request, &GetAllMappingsRequest::finished, this, [this](GetAllMappingsRequest* request) {\n-        qDebug() << \"Got\" << request->getMappings().size() << \"mappings!\";\n+    static constexpr quint64 MAX_REFRESH_TIME = 15 * 60 * 1000 * 1000;\n+    if (usecTimestampNow() - _lastMappingsRefresh > MAX_REFRESH_TIME) {\n+        qCWarning(backup_supervisor) << \"Backing up asset mappings that appear old.\";\n+    }\n \n-        if (request->getError() != MappingRequest::NoError) {\n-            qCritical() << \"Could not complete backup.\";\n-            qCritical() << \"    Error:\" << request->getErrorString();\n-            finishBackup();\n-            request->deleteLater();\n-            return;\n+    startOperation();\n+\n+    auto it = find_if(begin(_backups), end(_backups), [&](const std::vector<AssetServerBackup>::value_type& value) {\n+        return value.filePath == zip.getZipName();\n+    });\n+    if (it == end(_backups)) {\n+        qCDebug(backup_supervisor) << \"Could not find backup\";\n+        stopOperation();\n+        return;\n+    }\n+\n+    const auto& newMappings = it->mappings;\n+    computeServerStateDifference(_currentMappings, newMappings);\n+\n+    restoreAllAssets();\n+}\n+\n+void BackupSupervisor::deleteBackup(QuaZip& zip) {\n+    if (operationInProgress()) {\n+        qCWarning(backup_supervisor) << \"There is a backup/restore in progress.\";\n+        return;\n+    }\n+\n+    auto it = find_if(begin(_backups), end(_backups), [&](const std::vector<AssetServerBackup>::value_type& value) {\n+        return value.filePath == zip.getZipName();\n+    });\n+    if (it == end(_backups)) {\n+        qCDebug(backup_supervisor) << \"Could not find backup\";","path":"domain-server/src/BackupSupervisor.cpp","position":262,"original_position":283,"commit_id":"10d446d315f1db48dbbdc3897aec7ef181a63d65","original_commit_id":"10d446d315f1db48dbbdc3897aec7ef181a63d65","user":{"login":"birarda","id":724069,"avatar_url":"https://avatars2.githubusercontent.com/u/724069?v=4","gravatar_id":"","url":"https://api.github.com/users/birarda","html_url":"https://github.com/birarda","followers_url":"https://api.github.com/users/birarda/followers","following_url":"https://api.github.com/users/birarda/following{/other_user}","gists_url":"https://api.github.com/users/birarda/gists{/gist_id}","starred_url":"https://api.github.com/users/birarda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/birarda/subscriptions","organizations_url":"https://api.github.com/users/birarda/orgs","repos_url":"https://api.github.com/users/birarda/repos","events_url":"https://api.github.com/users/birarda/events{/privacy}","received_events_url":"https://api.github.com/users/birarda/received_events","type":"User","site_admin":false},"body":"Could not find backup $NAME to delete","created_at":"2018-02-14T23:03:02Z","updated_at":"2018-02-14T23:12:40Z","html_url":"https://github.com/highfidelity/hifi/pull/12404#discussion_r168338718","pull_request_url":"https://api.github.com/repos/highfidelity/hifi/pulls/12404","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/168338718"},"html":{"href":"https://github.com/highfidelity/hifi/pull/12404#discussion_r168338718"},"pull_request":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/12404"}}},"pull_request":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/12404","id":169239703,"html_url":"https://github.com/highfidelity/hifi/pull/12404","diff_url":"https://github.com/highfidelity/hifi/pull/12404.diff","patch_url":"https://github.com/highfidelity/hifi/pull/12404.patch","issue_url":"https://api.github.com/repos/highfidelity/hifi/issues/12404","number":12404,"state":"open","locked":false,"title":"Feat Asset Server backups integration","user":{"login":"Atlante45","id":4036492,"avatar_url":"https://avatars0.githubusercontent.com/u/4036492?v=4","gravatar_id":"","url":"https://api.github.com/users/Atlante45","html_url":"https://github.com/Atlante45","followers_url":"https://api.github.com/users/Atlante45/followers","following_url":"https://api.github.com/users/Atlante45/following{/other_user}","gists_url":"https://api.github.com/users/Atlante45/gists{/gist_id}","starred_url":"https://api.github.com/users/Atlante45/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Atlante45/subscriptions","organizations_url":"https://api.github.com/users/Atlante45/orgs","repos_url":"https://api.github.com/users/Atlante45/repos","events_url":"https://api.github.com/users/Atlante45/events{/privacy}","received_events_url":"https://api.github.com/users/Atlante45/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-02-14T22:28:32Z","updated_at":"2018-02-14T23:12:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1f51ecdf5a41dbda6e1885cee9820353ba15440b","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":794364211,"url":"https://api.github.com/repos/highfidelity/hifi/labels/Server%20&%20Network","name":"Server & Network","color":"f2bf8a","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/highfidelity/hifi/pulls/12404/commits","review_comments_url":"https://api.github.com/repos/highfidelity/hifi/pulls/12404/comments","review_comment_url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/highfidelity/hifi/issues/12404/comments","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/10d446d315f1db48dbbdc3897aec7ef181a63d65","head":{"label":"Atlante45:feat/backups-integration","ref":"feat/backups-integration","sha":"10d446d315f1db48dbbdc3897aec7ef181a63d65","user":{"login":"Atlante45","id":4036492,"avatar_url":"https://avatars0.githubusercontent.com/u/4036492?v=4","gravatar_id":"","url":"https://api.github.com/users/Atlante45","html_url":"https://github.com/Atlante45","followers_url":"https://api.github.com/users/Atlante45/followers","following_url":"https://api.github.com/users/Atlante45/following{/other_user}","gists_url":"https://api.github.com/users/Atlante45/gists{/gist_id}","starred_url":"https://api.github.com/users/Atlante45/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Atlante45/subscriptions","organizations_url":"https://api.github.com/users/Atlante45/orgs","repos_url":"https://api.github.com/users/Atlante45/repos","events_url":"https://api.github.com/users/Atlante45/events{/privacy}","received_events_url":"https://api.github.com/users/Atlante45/received_events","type":"User","site_admin":false},"repo":{"id":11436474,"name":"hifi","full_name":"Atlante45/hifi","owner":{"login":"Atlante45","id":4036492,"avatar_url":"https://avatars0.githubusercontent.com/u/4036492?v=4","gravatar_id":"","url":"https://api.github.com/users/Atlante45","html_url":"https://github.com/Atlante45","followers_url":"https://api.github.com/users/Atlante45/followers","following_url":"https://api.github.com/users/Atlante45/following{/other_user}","gists_url":"https://api.github.com/users/Atlante45/gists{/gist_id}","starred_url":"https://api.github.com/users/Atlante45/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Atlante45/subscriptions","organizations_url":"https://api.github.com/users/Atlante45/orgs","repos_url":"https://api.github.com/users/Atlante45/repos","events_url":"https://api.github.com/users/Atlante45/events{/privacy}","received_events_url":"https://api.github.com/users/Atlante45/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Atlante45/hifi","description":"Test platform for various render and interface tests for next-gen VR system","fork":true,"url":"https://api.github.com/repos/Atlante45/hifi","forks_url":"https://api.github.com/repos/Atlante45/hifi/forks","keys_url":"https://api.github.com/repos/Atlante45/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Atlante45/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Atlante45/hifi/teams","hooks_url":"https://api.github.com/repos/Atlante45/hifi/hooks","issue_events_url":"https://api.github.com/repos/Atlante45/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/Atlante45/hifi/events","assignees_url":"https://api.github.com/repos/Atlante45/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/Atlante45/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/Atlante45/hifi/tags","blobs_url":"https://api.github.com/repos/Atlante45/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Atlante45/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Atlante45/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/Atlante45/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Atlante45/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/Atlante45/hifi/languages","stargazers_url":"https://api.github.com/repos/Atlante45/hifi/stargazers","contributors_url":"https://api.github.com/repos/Atlante45/hifi/contributors","subscribers_url":"https://api.github.com/repos/Atlante45/hifi/subscribers","subscription_url":"https://api.github.com/repos/Atlante45/hifi/subscription","commits_url":"https://api.github.com/repos/Atlante45/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/Atlante45/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/Atlante45/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/Atlante45/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/Atlante45/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/Atlante45/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Atlante45/hifi/merges","archive_url":"https://api.github.com/repos/Atlante45/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Atlante45/hifi/downloads","issues_url":"https://api.github.com/repos/Atlante45/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/Atlante45/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/Atlante45/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/Atlante45/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Atlante45/hifi/labels{/name}","releases_url":"https://api.github.com/repos/Atlante45/hifi/releases{/id}","deployments_url":"https://api.github.com/repos/Atlante45/hifi/deployments","created_at":"2013-07-15T23:52:30Z","updated_at":"2015-05-08T13:17:34Z","pushed_at":"2018-02-14T02:38:32Z","git_url":"git://github.com/Atlante45/hifi.git","ssh_url":"git@github.com:Atlante45/hifi.git","clone_url":"https://github.com/Atlante45/hifi.git","svn_url":"https://github.com/Atlante45/hifi","homepage":null,"size":453543,"stargazers_count":1,"watchers_count":1,"language":"C++","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":"other","name":"Other","spdx_id":null,"url":null},"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"highfidelity:feat/content-settings","ref":"feat/content-settings","sha":"4f86bb030c200979d54d823db9a8f97fcb7226c8","user":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars0.githubusercontent.com/u/1565370?v=4","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"repo":{"id":5372872,"name":"hifi","full_name":"highfidelity/hifi","owner":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars0.githubusercontent.com/u/1565370?v=4","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/highfidelity/hifi","description":"Open source client/server software for creating shared VR environments.  Docs at http://docs.highfidelity.com  We are hiring: http://highfidelity.com/jobs  Also, PT work available at http://worklist.net","fork":false,"url":"https://api.github.com/repos/highfidelity/hifi","forks_url":"https://api.github.com/repos/highfidelity/hifi/forks","keys_url":"https://api.github.com/repos/highfidelity/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/highfidelity/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/highfidelity/hifi/teams","hooks_url":"https://api.github.com/repos/highfidelity/hifi/hooks","issue_events_url":"https://api.github.com/repos/highfidelity/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/highfidelity/hifi/events","assignees_url":"https://api.github.com/repos/highfidelity/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/highfidelity/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/highfidelity/hifi/tags","blobs_url":"https://api.github.com/repos/highfidelity/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/highfidelity/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/highfidelity/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/highfidelity/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/highfidelity/hifi/languages","stargazers_url":"https://api.github.com/repos/highfidelity/hifi/stargazers","contributors_url":"https://api.github.com/repos/highfidelity/hifi/contributors","subscribers_url":"https://api.github.com/repos/highfidelity/hifi/subscribers","subscription_url":"https://api.github.com/repos/highfidelity/hifi/subscription","commits_url":"https://api.github.com/repos/highfidelity/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/highfidelity/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/highfidelity/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/highfidelity/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/highfidelity/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/highfidelity/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/highfidelity/hifi/merges","archive_url":"https://api.github.com/repos/highfidelity/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/highfidelity/hifi/downloads","issues_url":"https://api.github.com/repos/highfidelity/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/highfidelity/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/highfidelity/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/highfidelity/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/highfidelity/hifi/labels{/name}","releases_url":"https://api.github.com/repos/highfidelity/hifi/releases{/id}","deployments_url":"https://api.github.com/repos/highfidelity/hifi/deployments","created_at":"2012-08-10T18:26:22Z","updated_at":"2018-02-14T04:54:50Z","pushed_at":"2018-02-14T23:03:43Z","git_url":"git://github.com/highfidelity/hifi.git","ssh_url":"git@github.com:highfidelity/hifi.git","clone_url":"https://github.com/highfidelity/hifi.git","svn_url":"https://github.com/highfidelity/hifi","homepage":"","size":465286,"stargazers_count":585,"watchers_count":585,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":392,"mirror_url":null,"archived":false,"open_issues_count":136,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":392,"open_issues":136,"watchers":585,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/12404"},"html":{"href":"https://github.com/highfidelity/hifi/pull/12404"},"issue":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/12404"},"comments":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/12404/comments"},"review_comments":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/12404/comments"},"review_comment":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/12404/commits"},"statuses":{"href":"https://api.github.com/repos/highfidelity/hifi/statuses/10d446d315f1db48dbbdc3897aec7ef181a63d65"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"birarda"}}