@@ -49,6 +49,7 @@ type LibrariesDir struct {
4949 Path * paths.Path
5050 Location libraries.LibraryLocation
5151 PlatformRelease * cores.PlatformRelease
52+ IsSingleLibrary bool // true if Path points directly to a library instad of a dir of libraries
5253}
5354
5455var tr = i18n .Tr
@@ -102,46 +103,28 @@ func (lm *LibrariesManager) LoadIndex() error {
102103// AddLibrariesDir adds path to the list of directories
103104// to scan when searching for libraries. If a path is already
104105// 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 {
124108 return
125109 }
126110 for _ , dir := range lm .LibrariesDir {
127- if dir .Path .EquivalentTo (path ) {
111+ if dir .Path .EquivalentTo (libDir . Path ) {
128112 return
129113 }
130114 }
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 )
137120}
138121
139122// RescanLibraries reload all installed libraries in the system.
140123func (lm * LibrariesManager ) RescanLibraries () []* status.Status {
141124 lm .clearLibraries ()
142125 statuses := []* status.Status {}
143126 for _ , dir := range lm .LibrariesDir {
144- if errs := lm .LoadLibrariesFromDir (dir ); len (errs ) > 0 {
127+ if errs := lm .loadLibrariesFromDir (dir ); len (errs ) > 0 {
145128 statuses = append (statuses , errs ... )
146129 }
147130 }
@@ -164,22 +147,29 @@ func (lm *LibrariesManager) getLibrariesDir(installLocation libraries.LibraryLoc
164147 }
165148}
166149
167- // LoadLibrariesFromDir loads all libraries in the given directory. Returns
150+ // loadLibrariesFromDir loads all libraries in the given directory. Returns
168151// 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 {
170153 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
178170 }
179- subDirs .FilterDirs ()
180- subDirs .FilterOutHiddenFiles ()
181171
182- for _ , subDir := range subDirs {
172+ for _ , subDir := range libDirs {
183173 library , err := libraries .Load (subDir , librariesDir .Location )
184174 if err != nil {
185175 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) []*
195185 return statuses
196186}
197187
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-
217188// FindByReference return the installed libraries matching the Reference
218189// name and version or, if the version is nil, the libraries installed
219190// in the installLocation.
0 commit comments