-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implementation of XDG File specification and a basic implementation of HTTPCookieStorage #889
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
Conversation
The testing is absolutely the hardest part of this; we also need a way to start new child processes with new environment variables to make sure everything is configured correctly. |
I have written to the community for ideas to get the tests done. Only way I could think of now is to use the existing APIs (one example being HTTPCookieStorage API) that use these environmental variables to get a part of the tests done. Need to check on where the remaining environmental variable usage would fit in. Regarding the "start new child processes with new environment variables to make sure everything is configured correctly", does this mean that we would be setting the environmental variables using these child processes and the test API is expected to reflect the values set? |
Yes, probably we'll need to create a helper process that gets launched via |
@parkera Ok, will get onto it. Meanwhile, request you to review the implementation thus far. |
Yup, looks reasonable so far. Thanks! |
@parkera By mentioning "Then we need that process to use some existing API that would be affected by the presence of the environment variables (preferences, maybe?)", did you mean to use the NSUserDefaults on Foundation? |
Yes, that would be a good candidate. |
@parkera At the outlook, the NSUserDefaults code on Linux currently does not look complete. I see api code in it being commented stating compiler failures / code confined to only OS x/ iOS platforms / unimplemented api and also the test-cases on TestFoundation are commented out.
On a search done in Foundation for 'standardUserDefaults' , the results do not yield the setting or use of this elsewhere. This implies that there is no default value set on Linux? |
Hello @mamabusi I found this to be a good read about suite names and such: CFXMLPreferencesDomain.c may be the simplest way to get things working; it seems to have been checked in[1], but some other changes in CF are needed[2] TestNSUserDefaults.swift has
|
User defaults are simply property lists (which can be XML or binary), which is basically the lingua franca of CoreFoundation. I don't think there is much value in changing the format; but if we did it would be orthogonal to getting the basic API working. I do want to keep the CFPrefs concept of search lists in place, although some (like the network home) will not make sense on this platform. Maybe instead of user defaults, which has its own set of challenges here, we should focus on the use case which got us here in the first place? I think that was where |
@mamabusi I will update the HTTPCookieStorage PR by early next week, its been a while |
@parkera Could the commit of HTTPCookieStorage be combined with this? |
@pushkarnk Cool. Once the changes are in place for using the XDG variable, I'll verify the correctness of the path retrieval in HTTPCookieStorage. Thanks! |
@parkera I set the environment variable using the Foundation Api: Retrieved it using the api: I could fetch the variable that is set. Whereas, on the CoreFoundation when I try to fetch this using the API __CFgetenv(), I see that the variable is not set. Wondering what is the reason that it is not reflecting on the CoreFoundation side. Do they refer to different scopes of environment? Aren’t all of these running in the same process? Also, if I have to set the system-wide environment variables (in this case the XDG variables should be system-wide) after much reading I figured out that it is not possible programmatically. Hence, I would have to do it by launching a script file that would edit the system (read-only) files that require the root access of the machine where the tests are to be run. Is this a feasible option? Or is there a alternative that is already being used in TestFoundation? Am I missing something here? Thanks! |
|
f4c3182
to
c013c5c
Compare
fe63707
to
0c05efd
Compare
@@ -417,6 +417,7 @@ class SwiftExecutable(BuildPhase): | |||
def __init__(self, executableName, sources): | |||
BuildAction.__init__(self, output=executableName) | |||
self.executableName = executableName | |||
self.name = executableName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a dependency of the executable creation for XDG to foundation_tests (which is the SwiftExecutable: Test Foundation) in build.py caused a script failure here as the 'name' seemed to be 'nil'. Hence, the change.
@pushkarnk Have cherry picked your HTTPCookieStorage implementation and modified the same to use the environment variable of XDG file specification. Please review. @parkera Have added test-case for XDG file specification implementation. Please review. Thanks! |
@swift-ci please test |
1 similar comment
@swift-ci please test |
Third time again! |
Looks like a swiftpm failure:
|
a2c0308
to
78d865e
Compare
78d865e
to
168402f
Compare
} | ||
// Add count for trailing path unless ending with colon. | ||
pathCount += last_colon < (values + strlen(values) - 1); | ||
if (pathCount > 64) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Limits the number of paths to 64 and returns an empty array if pathCount exceeds 64.
CFArrayRef dataDirPathsArray = _CFCreateCFArrayByTokenizingString(dataDirectoriesPaths, ':'); | ||
if(CFArrayGetCount(dataDirPathsArray) == 0) { | ||
CFStringRef logMessage = CFSTR("Value set in XDG_DATA_DIRS variable not honoured. Returning the default."); | ||
CFLog(kCFLogLevelWarning, CFSTR("%@"), logMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of the pathCount > 64 or all the paths in the variable turn out to be invalid, an empty array is returned. At such times the default path is returned although the variable was set. The log warning message gives a hint.
CFArrayRef configDirPathsArray = _CFCreateCFArrayByTokenizingString(configDirectoriesPaths, ':'); | ||
if(CFArrayGetCount(configDirPathsArray) == 0) { | ||
CFStringRef logMessage = CFSTR("Value set in XDG_CONFIG_DIRS variable not honoured. Returning the default."); | ||
CFLog(kCFLogLevelWarning, CFSTR("%@"), logMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of the pathCount > 64 or all the paths in the variable turn out to be invalid, an empty array is returned. At such times the default path is returned although the variable was set. The log warning message gives a hint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok; one more thing now - we need to release configDirPathsArray
here before returning, otherwise we leak it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parkera Sorry I missed that. Done now.
@parkera Addressed the requested changes. Please take a look. |
168402f
to
8451b05
Compare
@swift-ci please test |
Looks like the tests didn't run @swift-ci please test |
@parkera All the review changes are completed. Please let me know if something is missed. |
Thanks @mamabusi! Let's get this merged. |
Yay! Thanks a ton for all the guidance @parkera |
No problem, thank you for finishing this up. |
I know this has been merged already, but I don't think the current paths for cookie storage are appropriate. Firstly, Secondly, none of my Linux machines (Arch Linux and Ubuntu) contain any files in either
This to me seems like reason enough to put any files Swift creates in a dedicated subfolder as well. This subfolder should probably be a separate folder per application, but see the following paragraphs for that. Finally, the current implementation uses the same shared storage for all users of the api, while that behavior was removed from OSX Foundation. The doc comment of
I think it would be reasonable for the Linux implementation to have the same behaviour, although that change might be better to hold back until corelibs-foundation has a more fleshed-out concept of different directories on Linux including implementing |
Those comments do make sense to me. It would be good to get them into a bug on bugs.swift.org, and perhaps follow up with a discussion on swift-corelibs-dev mailing list. |
@mamabusi can you take a look at this? |
@ahti Thanks for the suggestions. Regarding "Starting in OS X 10.11, each app has its own sharedHTTPCookieStorage singleton, which will not be shared with other applications" I will modify the current implementation on Linux to match that of Darwin. Thanks! |
Sorry, I've been quite busy the past week. @mamabusi Sounds good. Should I still file a bug in jira? |
@ahti Yes, please go ahead and file a bug for this in JIRA. Thanks! |
This is an unpolished implementation of the XDG File specification. Have referred to related work started by Tony Parker in the repo: https://github.com/parkera/swift-corelibs-foundation/tree/parkera/xdg_implementation
Note that the tests for the API implementation have been done on my local build setup. The same are not available in the committed changes here as they involve adding API in the Foundation to access the CoreFoundation implementation that is done.
Please suggest if there is an alternate way of adding tests.