execute()
功能与按下按钮相关联。
它第一次被按下 - 一切都按照应该的方式运行/
第二次被按下(在应用程序的同一执行中;如果我关闭并重新打开它工作正常) - 在DeleteAsync
行我得到这个例外:
发生了'System.UnauthorizedAccessException'类型的异常 mscorlib.ni.dll但未在用户代码中处理
其他信息:访问被拒绝。 (HRESULT的例外情况: 0x80070005(E_ACCESSDENIED))
我认为某些东西比它应该保持更长时间,因此错误。但我不确定究竟是什么导致了它。如果有人能从下面的代码中看到可能发生的事情,我将非常感激:
private async void execute(string url)
{
StorageFolder filesFolder = null;
StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
if (await localFolder.TryGetItemAsync(DIRECTORY_NAME) != null)
{
filesFolder = await localFolder.GetFolderAsync(DIRECTORY_NAME);
await filesFolder.DeleteAsync(StorageDeleteOption.PermanentDelete); // << THIS IS THE EXCEPTION LINE
}
if (await localFolder.TryGetItemAsync(DIRECTORY_NAME) == null)
{
await Task.Run(() => {
repository.Clone(url, DIRECTORY_NAME);
});
}
// This won't be called until task above finished running
filesFolder = await localFolder.GetFolderAsync(DIRECTORY_NAME);
IEnumerable<StorageFile> files = await filesFolder.GetFilesAsync();
addFiles(files);
}
克隆功能:
void Repository::Clone(Platform::String^ url, Platform::String^ path)
{
OutputDebugString(L"Clone ");
OutputDebugString(url->Data());
OutputDebugString(L" into ");
char temp[1024];
GetLocalPath(path, temp, 1024);
OutputDebugStringA(temp);
OutputDebugString(L"\n");
char urlt[1024];
wcstombs(urlt, url->Data(), 1024);
git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
// Set up options
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
checkout_opts.progress_cb = on_checkout_progress;
clone_opts.checkout_opts = checkout_opts;
clone_opts.fetch_opts.callbacks.sideband_progress = on_sideband_progress;
clone_opts.fetch_opts.callbacks.transfer_progress = on_fetch_transfer_progress;
clone_opts.fetch_opts.callbacks.credentials = on_credentials_required;
clone_opts.fetch_opts.callbacks.payload = this->native;
// Start the cloning
report_error(git_clone(&repo, urlt, temp, &clone_opts));
}