Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for containerURLs through publisher cache folders #2384

Merged
merged 3 commits into from
Apr 4, 2017

Conversation

aballway
Copy link
Contributor

The reference platform has a concept of an application-group entitlement which allows apps made by the same publisher to share folders and semaphores. The shared folders can be accessed through -[NSFileManager containerURLForSecurityApplicationGroupIdentifier:] which will return an NSURL pointing to the shared folder with the given name if one exists.

These folders are declared in an entitlements file separate from the main .pbxproj and info.plist where other settings are stored, and is pointed at by the value with key CODE_SIGN_ENTITLEMENTS in the PBXNativeTarget's Build Configurations.

Here, the shared folders are implemented using Windows' Publisher Cache Folders, which also allow files to be shared in designated folders between apps of the same publisher, but with the caveat that users can clear the data at any time so it should not be used as the sole storage for key data.

VSImporter has been modified to check if CODE_SIGN_ENTITLEMENTS exists, and if it does, read the file and look for com.apple.security.application-groups, which will contain an array of folder names which are to be shared. The reference platform specifies the format which folders must be named, but Publisher Cache Folders does not have such a restriction for names so any valid folder names will be taken and used.

-[NSFileManager containerURLForSecurityApplicationGroupIdentifier:] is implemented by checking if a Publisher Cache Folder of the given name, and if it does returning an NSURL to it.

Fixes #2295
Fixes #2307


#include <COMIncludes.h>
#import <windows.storage.h>
#import <wrl\client.h>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standardize on /

ComPtr<IStorageItem> storageItem;
RETURN_NULL_IF_FAILED(folder.As(&storageItem));

HSTRING folderPath;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want a HStringReference here; i think get_Path will return a +1 HSTRING, and you'll leak it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, spent too much time with CF, got used to Get = 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You actually want a Wrappers::HString https://msdn.microsoft.com/en-us/library/hh771141.aspx

HStringReference is for a reference to an existing string resource to avoid copies.


In reply to: 109047974 [](ancestors = 109047974)

String m_productType;
StringVec m_buildRuleIds;
/* End of serialized values */

PBXFileReference* m_productReferencePtr;
BuildRuleList m_buildRulePtrs;
XCConfigurationList* m_nativeBuildConfigurationListPtr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XCConfigurationList* [](start = 3, length = 21)

this is fine as a raw ptr? do we not own the config list here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not, it is just a pointer to an object owned by the pbxDoc. Ideally it would be a shared_ptr but that's a lot more fixing than I want to do for this change set.

extension +=
" </PublisherCacheFolders>\n"
" </Extension>\n";
ret.emplace_back(extension);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extension [](start = 25, length = 9)

should you std move extension here?

pDict = boost::any_cast<Plist::dictionary_type>(&pAny);
} catch (const std::exception& e) {
SBLog::error() << e.what() << std::endl;
pDict = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pDict = nullptr; [](start = 12, length = 20)

move this up to the declaration?

@bbowman
Copy link
Member

bbowman commented Mar 31, 2017

:shipit:


static const wchar_t* TAG = L"NSFileManager";

using namespace Microsoft::WRL;
using namespace ABI::Windows::Storage;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can get rid of the #ifdef linux code here.

// Dispose of any resources that can be recreated.
}

- (void)readFile {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want to add a negative test here trying to read folder2?

" </PublisherCacheFolders>\n"
" </Extension>\n";
ret.emplace_back(extension);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pugixml for this. See VSTemplateProject.cpp.

@@ -43,6 +43,8 @@
</Application>
</Applications>

$extensions$
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$extensions$ [](start = 2, length = 12)

Use in combination with pugixml instead

String ret = "";
buildSettings.getValue("CODE_SIGN_ENTITLEMENTS", ret);
return ret;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SBResourcesBuildPhase.cpp does this simpler. See SBResourcesBuildPhase::writeVCProjectFiles:
String plistPath = bs.second->getValue("INFOPLIST_FILE");

@memontic-ms
Copy link
Contributor

🕐

extensionsOutput += " </Extensions>";
m_params["$extensions$"] = extensionsOutput;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't seem to be using this function anymore. Revert changes in VSTemplateParameters.cpp/h

Plist::dictionary_type* pDict = nullptr;
boost::any pAny;
try {
Plist::readPlist(entitlementsPath.c_str(), pAny);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plist::readPlist(entitlementsPath.c_str(), pAny); [](start = 8, length = 49)

Needs to be relative to xcodeproj or something, not relative to the current dir.

static void insertUrlSchemes(const String& file, const StringSet& schemes) {
//
// Inject registered URL schemes into the AppX manifest file, in this format:
static std::vector<String> getCacheFolders(const String& entitlementsPath) {
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram Apr 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getCacheFolders [](start = 27, length = 15)

return this by ref vs making a copy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler should elide this copy #ByDesign

SBLog::error() << e.what() << std::endl;
}

if (pDict) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: a comment here would be nice

@@ -16,6 +16,7 @@

#include <iostream>
#include <iterator>
#include <memory>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused include

@@ -21,6 +21,8 @@
#include "PBXBuildRule.h"
#include "PBXObjectIdConvert.h"
#include "VariableCollection.h"
#include "XCBuildConfiguration.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused includes

@@ -67,6 +67,7 @@ class SBProject {
void queryBuildConfigurations();
void selectBuildConfigurations(const StringSet* configNames);
void getMatchingFiles(fileMatchFunc matchFunc, ConstFileList& ret) const;
std::vector<std::string> SBProject::getPublisherCacheFolderNames() const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove. This is never defined/used.

@aballway aballway merged commit 3438f59 into microsoft:develop Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants