@@ -178,36 +178,49 @@ ly_ctx_get_searchdirs(const struct ly_ctx *ctx)
178178}
179179
180180LIBYANG_API_DEF LY_ERR
181- ly_ctx_unset_searchdir (struct ly_ctx * ctx , const char * value )
181+ ly_ctx_unset_searchdir (struct ly_ctx * ctx , const char * search_dir )
182182{
183+ LY_ERR rc = LY_SUCCESS ;
184+ uint32_t index ;
185+ char * search_dir_real = NULL ;
186+
183187 LY_CHECK_ARG_RET (ctx , ctx , !(ctx -> opts & LY_CTX_INT_IMMUTABLE ), LY_EINVAL );
184188
185189 if (!ctx -> search_paths .count ) {
186190 return LY_SUCCESS ;
187191 }
188192
189- if (value ) {
190- /* remove specific search directory */
191- uint32_t index ;
193+ if (search_dir ) {
194+ search_dir_real = realpath (search_dir , NULL );
195+ if (!search_dir_real ) {
196+ LOGERR (ctx , LY_EINVAL , "Unable to normalize search directory \"%s\" (%s)." , search_dir , strerror (errno ));
197+ rc = LY_EINVAL ;
198+ goto cleanup ;
199+ }
192200
201+ /* remove specific search directory */
193202 for (index = 0 ; index < ctx -> search_paths .count ; ++ index ) {
194- if (!strcmp (value , ctx -> search_paths .objs [index ])) {
203+ if (!strcmp (search_dir_real , ctx -> search_paths .objs [index ])) {
195204 break ;
196205 }
197206 }
198207 if (index == ctx -> search_paths .count ) {
199- LOGARG (ctx , value );
200- return LY_EINVAL ;
208+ LOGARG (ctx , search_dir_real );
209+ rc = LY_EINVAL ;
210+ goto cleanup ;
201211 } else {
202- return ly_set_rm_index (& ctx -> search_paths , index , free );
212+ rc = ly_set_rm_index (& ctx -> search_paths , index , free );
213+ goto cleanup ;
203214 }
204215 } else {
205216 /* remove them all */
206217 ly_set_erase (& ctx -> search_paths , free );
207218 memset (& ctx -> search_paths , 0 , sizeof ctx -> search_paths );
208219 }
209220
210- return LY_SUCCESS ;
221+ cleanup :
222+ free (search_dir_real );
223+ return rc ;
211224}
212225
213226LIBYANG_API_DEF LY_ERR
0 commit comments