@@ -49,6 +49,7 @@ type LibrariesDir struct {
49
49
Path * paths.Path
50
50
Location libraries.LibraryLocation
51
51
PlatformRelease * cores.PlatformRelease
52
+ IsSingleLibrary bool // true if Path points directly to a library instad of a dir of libraries
52
53
}
53
54
54
55
var tr = i18n .Tr
@@ -102,46 +103,28 @@ func (lm *LibrariesManager) LoadIndex() error {
102
103
// AddLibrariesDir adds path to the list of directories
103
104
// to scan when searching for libraries. If a path is already
104
105
// in the list it is ignored.
105
- func (lm * LibrariesManager ) AddLibrariesDir (path * paths.Path , location libraries.LibraryLocation ) {
106
- for _ , dir := range lm .LibrariesDir {
107
- if dir .Path .EquivalentTo (path ) {
108
- return
109
- }
110
- }
111
- logrus .WithField ("dir" , path ).WithField ("location" , location .String ()).Info ("Adding libraries dir" )
112
- lm .LibrariesDir = append (lm .LibrariesDir , & LibrariesDir {
113
- Path : path ,
114
- Location : location ,
115
- })
116
- }
117
-
118
- // AddPlatformReleaseLibrariesDir add the libraries directory in the
119
- // specified PlatformRelease to the list of directories to scan when
120
- // searching for libraries.
121
- func (lm * LibrariesManager ) AddPlatformReleaseLibrariesDir (plaftormRelease * cores.PlatformRelease , location libraries.LibraryLocation ) {
122
- path := plaftormRelease .GetLibrariesDir ()
123
- if path == nil {
106
+ func (lm * LibrariesManager ) AddLibrariesDir (libDir * LibrariesDir ) {
107
+ if libDir .Path == nil {
124
108
return
125
109
}
126
110
for _ , dir := range lm .LibrariesDir {
127
- if dir .Path .EquivalentTo (path ) {
111
+ if dir .Path .EquivalentTo (libDir . Path ) {
128
112
return
129
113
}
130
114
}
131
- logrus .WithField ("dir" , path ).WithField ("location" , location .String ()).Info ("Adding libraries dir" )
132
- lm .LibrariesDir = append (lm .LibrariesDir , & LibrariesDir {
133
- Path : path ,
134
- Location : location ,
135
- PlatformRelease : plaftormRelease ,
136
- })
115
+ logrus .WithField ("dir" , libDir .Path ).
116
+ WithField ("location" , libDir .Location .String ()).
117
+ WithField ("isSingleLibrary" , libDir .IsSingleLibrary ).
118
+ Info ("Adding libraries dir" )
119
+ lm .LibrariesDir = append (lm .LibrariesDir , libDir )
137
120
}
138
121
139
122
// RescanLibraries reload all installed libraries in the system.
140
123
func (lm * LibrariesManager ) RescanLibraries () []* status.Status {
141
124
lm .clearLibraries ()
142
125
statuses := []* status.Status {}
143
126
for _ , dir := range lm .LibrariesDir {
144
- if errs := lm .LoadLibrariesFromDir (dir ); len (errs ) > 0 {
127
+ if errs := lm .loadLibrariesFromDir (dir ); len (errs ) > 0 {
145
128
statuses = append (statuses , errs ... )
146
129
}
147
130
}
@@ -164,22 +147,29 @@ func (lm *LibrariesManager) getLibrariesDir(installLocation libraries.LibraryLoc
164
147
}
165
148
}
166
149
167
- // LoadLibrariesFromDir loads all libraries in the given directory. Returns
150
+ // loadLibrariesFromDir loads all libraries in the given directory. Returns
168
151
// nil if the directory doesn't exists.
169
- func (lm * LibrariesManager ) LoadLibrariesFromDir (librariesDir * LibrariesDir ) []* status.Status {
152
+ func (lm * LibrariesManager ) loadLibrariesFromDir (librariesDir * LibrariesDir ) []* status.Status {
170
153
statuses := []* status.Status {}
171
- subDirs , err := librariesDir .Path .ReadDir ()
172
- if os .IsNotExist (err ) {
173
- return statuses
174
- }
175
- if err != nil {
176
- s := status .Newf (codes .FailedPrecondition , tr ("reading dir %[1]s: %[2]s" ), librariesDir .Path , err )
177
- return append (statuses , s )
154
+
155
+ var libDirs paths.PathList
156
+ if librariesDir .IsSingleLibrary {
157
+ libDirs .Add (librariesDir .Path )
158
+ } else {
159
+ d , err := librariesDir .Path .ReadDir ()
160
+ if os .IsNotExist (err ) {
161
+ return statuses
162
+ }
163
+ if err != nil {
164
+ s := status .Newf (codes .FailedPrecondition , tr ("reading dir %[1]s: %[2]s" ), librariesDir .Path , err )
165
+ return append (statuses , s )
166
+ }
167
+ d .FilterDirs ()
168
+ d .FilterOutHiddenFiles ()
169
+ libDirs = d
178
170
}
179
- subDirs .FilterDirs ()
180
- subDirs .FilterOutHiddenFiles ()
181
171
182
- for _ , subDir := range subDirs {
172
+ for _ , subDir := range libDirs {
183
173
library , err := libraries .Load (subDir , librariesDir .Location )
184
174
if err != nil {
185
175
s := status .Newf (codes .Internal , tr ("loading library from %[1]s: %[2]s" ), subDir , err )
@@ -195,25 +185,6 @@ func (lm *LibrariesManager) LoadLibrariesFromDir(librariesDir *LibrariesDir) []*
195
185
return statuses
196
186
}
197
187
198
- // LoadLibraryFromDir loads one single library from the libRootDir.
199
- // libRootDir must point to the root of a valid library.
200
- // An error is returned if the path doesn't exist or loading of the library fails.
201
- func (lm * LibrariesManager ) LoadLibraryFromDir (libRootDir * paths.Path , location libraries.LibraryLocation ) error {
202
- if libRootDir .NotExist () {
203
- return fmt .Errorf (tr ("library path does not exist: %s" ), libRootDir )
204
- }
205
-
206
- library , err := libraries .Load (libRootDir , location )
207
- if err != nil {
208
- return fmt .Errorf (tr ("loading library from %[1]s: %[2]s" ), libRootDir , err )
209
- }
210
-
211
- alternatives := lm .Libraries [library .Name ]
212
- alternatives .Add (library )
213
- lm .Libraries [library .Name ] = alternatives
214
- return nil
215
- }
216
-
217
188
// FindByReference return the installed libraries matching the Reference
218
189
// name and version or, if the version is nil, the libraries installed
219
190
// in the installLocation.
0 commit comments