FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Strongbox/macbox/MacFileBasedBookmarkStorageProvider.m at master · MacPass/Strongbox · GitHub
MacPass
/
Strongbox
Public
forked from
strongbox-password-safe/Strongbox
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Strongbox
/
macbox
/
MacFileBasedBookmarkStorageProvider.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
232 lines (169 loc) · 8.16 KB
Breadcrumbs
Strongbox
/
macbox
/
MacFileBasedBookmarkStorageProvider.m
Copy path
File metadata and controls
232 lines (169 loc) · 8.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
//
//
MacFileBasedBookmarkStorageProvider.m
//
MacBox
//
//
Created by Strongbox on 22/03/2021.
//
Copyright © 2021 Mark McGuill. All rights reserved.
//
#
import
"
MacFileBasedBookmarkStorageProvider.h
"
#
import
"
BookmarksHelper.h
"
#
import
"
DatabasesManager.h
"
#
import
"
Utils.h
"
#
import
"
MacUrlSchemes.h
"
@implementation
MacFileBasedBookmarkStorageProvider
+ (
instancetype
)
sharedInstance
{
static
MacFileBasedBookmarkStorageProvider *sharedInstance =
nil
;
static
dispatch_once_t
onceToken;
dispatch_once
(&onceToken, ^{
sharedInstance = [[MacFileBasedBookmarkStorageProvider
alloc
]
init
];
});
return
sharedInstance;
}
- (
instancetype
)
init
{
if
(self = [
super
init
]) {
_storageId =
kMacFile
;
_providesIcons =
NO
;
_browsableNew =
NO
;
_browsableExisting =
NO
;
_rootFolderOnly =
NO
;
_defaultForImmediatelyOfferOfflineCache =
NO
;
_supportsConcurrentRequests =
NO
;
}
return
self;
}
- (
void
)
create
:
(nonnull
NSString
*)
nickName
extension
:
(nonnull
NSString
*)
extension
data
:
(nonnull
NSData
*)
data
parentFolder
:
(
NSObject
* _Nullable)
parentFolder
viewController
:
(
VIEW_CONTROLLER_PTR
_Nullable)
viewController
completion
:
(nonnull
void
(^)(
METADATA_PTR
_Nonnull,
const
NSError
* _Nonnull))completion {
}
- (
void
)
delete
:
(nonnull
METADATA_PTR
)
safeMetaData
completion
:
(nonnull
void
(^)(
const
NSError
* _Nullable))completion {
}
- (
METADATA_PTR
_Nullable)
getSafeMetaData
:
(nonnull
NSString
*)
nickName
providerData
:
(nonnull
NSObject
*)
providerData
{
return
nil
;
}
- (
void
)
list
:
(
NSObject
* _Nullable)
parentFolder
viewController
:
(
VIEW_CONTROLLER_PTR
_Nullable)
viewController
completion
:
(nonnull
void
(^)(
BOOL
,
NSArray
<StorageBrowserItem *> * _Nonnull,
const
NSError
* _Nonnull))completion {
}
- (
void
)
loadIcon
:
(nonnull
NSObject
*)
providerData
viewController
:
(nonnull
VIEW_CONTROLLER_PTR
)
viewController
completion
:
(nonnull
void
(^)(
IMAGE_TYPE_PTR
_Nonnull))completionHandler {
}
- (
void
)
pullDatabase
:
(nonnull
METADATA_PTR
)
safeMetaData
interactiveVC
:
(
VIEW_CONTROLLER_PTR
_Nullable)
viewController
options
:
(nonnull StorageProviderReadOptions *)
options
completion
:
(nonnull StorageProviderReadCompletionBlock)
completion
{
NSError
*error;
NSURL
* url = [
self
directFileUrlForDatabase:
safeMetaData
ppError:
&error];
if
(error || !url) {
NSLog
(
@"
Error or nil URL in Files App Provider:
%@
"
, error);
completion
(
kReadResultError
,
nil
,
nil
, error);
return
;
}
BOOL
securitySucceeded = [url
startAccessingSecurityScopedResource
];
if
(!securitySucceeded) {
NSLog
(
@"
Could not access secure scoped resource! Will try get attributes anyway...
"
);
}
NSDictionary
* attr = [
NSFileManager
.defaultManager
attributesOfItemAtPath:
url.path
error:
&error];
if
(error) {
NSLog
(
@"
Error getting attributes for files based Database, will try open anyway: [
%@
] - Attributes: [
%@
]
"
, error, attr);
}
NSError
*readError =
nil
;
NSData
* data = [
NSData
dataWithContentsOfURL:
url
options:
kNilOptions
error:
&readError];
if
( securitySucceeded ) {
[
self
stopAccessingSecurityScopedResource:
url];
}
if
( data && !readError ) {
completion
(
kReadResultSuccess
, data, attr ? attr.
fileModificationDate
:
nil
,
nil
);
}
else
{
completion
(
kReadResultError
,
nil
,
nil
, readError);
}
}
- (
void
)
getModDate
:
(
METADATA_PTR
)
safeMetaData
completion
:
(StorageProviderGetModDateCompletionBlock)
completion
{
NSError
*error;
NSURL
* url = [
self
directFileUrlForDatabase:
safeMetaData
ppError:
&error];
if
(error || !url) {
NSLog
(
@"
Error or nil URL in Files App Provider:
%@
"
, error);
completion
(
nil
, error);
return
;
}
BOOL
securitySucceeded = [url
startAccessingSecurityScopedResource
];
if
(!securitySucceeded) {
NSLog
(
@"
Could not access secure scoped resource! Will try get attributes anyway...
"
);
}
NSDictionary
* attr = [
NSFileManager
.defaultManager
attributesOfItemAtPath:
url.path
error:
&error];
if
(error) {
NSLog
(
@"
Error getting attributes for files based Database, will try open anyway: [
%@
] - Attributes: [
%@
]
"
, error, attr);
}
if
( securitySucceeded ) {
[
self
stopAccessingSecurityScopedResource:
url];
}
completion
(attr.
fileModificationDate
, error);
}
- (
void
)
pushDatabase
:
(nonnull
METADATA_PTR
)
safeMetaData
interactiveVC
:
(
VIEW_CONTROLLER_PTR
_Nullable)
viewController
data
:
(nonnull
NSData
*)
data
completion
:
(nonnull StorageProviderUpdateCompletionBlock)
completion
{
NSError
*error;
NSURL
* url = [
self
directFileUrlForDatabase:
safeMetaData
ppError:
&error];
if
(error) {
NSLog
(
@"
Error or nil URL in Files App provider: [
%@
]
"
, error);
completion
(
kUpdateResultError
,
nil
, error);
return
;
}
if
(!url || url.
absoluteString
.
length
==
0
) {
NSLog
(
@"
nil or empty URL in Files App provider
"
);
error = [Utils
createNSError:
[
NSString
stringWithFormat:
@"
Invalid URL in Files App Provider:
%@
"
, url]
errorCode:
-
1
];
completion
(
kUpdateResultError
,
nil
, error);
return
;
}
BOOL
securitySucceeded = [url
startAccessingSecurityScopedResource
];
if
(!securitySucceeded) {
NSLog
(
@"
Could not access secure scoped resource! Will try get attributes anyway...
"
);
}
BOOL
success = [data
writeToURL:
url
options:
kNilOptions
error:
&error];
NSDictionary
* attr = [
NSFileManager
.defaultManager
attributesOfItemAtPath:
url.path
error:
&error];
if
(error) {
NSLog
(
@"
Error getting attributes for files based Database, will try open anyway: [
%@
] - Attributes: [
%@
]
"
, error, attr);
}
if
( securitySucceeded ) {
[
self
stopAccessingSecurityScopedResource:
url];
}
if
( success ) {
completion
(
kUpdateResultSuccess
, attr ? attr.
fileModificationDate
:
nil
,
nil
);
}
else
{
NSError
*err = [Utils
createNSError:
NSLocalizedString(
@"
files_provider_problem_saving
"
,
@"
Problem Saving to External File
"
)
errorCode:
-
1
];
completion
(
kUpdateResultError
,
nil
, err);
}
}
- (
void
)
readWithProviderData
:
(
NSObject
* _Nullable)
providerData
viewController
:
(
VIEW_CONTROLLER_PTR
_Nullable)
viewController
options
:
(nonnull StorageProviderReadOptions *)
options
completion
:
(nonnull StorageProviderReadCompletionBlock)
completionHandler
{
}
- (
NSURL
*)
directFileUrlForDatabase
:
(
METADATA_PTR
)
database
ppError
:
(
NSError
**)
ppError
{
if
( database.
storageInfo
!=
nil
) {
NSError
*error =
nil
;
NSString
* updatedBookmark;
NSURL
*url = [BookmarksHelper
getUrlFromBookmark:
database.storageInfo
readOnly:
NO
updatedBookmark:
&updatedBookmark
error:
&error];
if
( url ==
nil
) {
NSLog
(
@"
WARN: Could not resolve bookmark for database... will try the saved fileUrl...
"
);
}
else
{
if
( updatedBookmark ) {
NSLog
(
@"
INFO: Bookmark has changed for Database updating...
"
);
database.
storageInfo
= updatedBookmark;
[DatabasesManager.sharedInstance
atomicUpdate:
database.uuid
touch:
^(DatabaseMetadata * _Nonnull metadata) {
metadata.
storageInfo
= updatedBookmark;
}];
}
NSURL
* defaultRet =
fileUrlFromManagedUrl
(database.
fileUrl
);
if
( ![url.absoluteString
isEqualToString:
defaultRet.absoluteString] ) {
NSLog
(
@"
INFO: URL has changed for Database updating...
"
);
database.
fileUrl
=
managedUrlFromFileUrl
(url);
[DatabasesManager.sharedInstance
atomicUpdate:
database.uuid
touch:
^(DatabaseMetadata * _Nonnull metadata) {
metadata.
fileUrl
= database.
fileUrl
;
}];
}
return
url;
}
}
return
fileUrlFromManagedUrl
(database.
fileUrl
);
}
- (
void
)
stopAccessingSecurityScopedResource
:
(
NSURL
*)
url
{
if
( @
available
(macOS
11.0
, *) ) {
[url
stopAccessingSecurityScopedResource
];
}
}
@end
Back
|
FazBrowse Home
|
New Git URL