context CHANGE refactor search dir check

First canonicalize the path and then check it.
diff --git a/src/context.c b/src/context.c
index 10542c0..393adbf 100644
--- a/src/context.c
+++ b/src/context.c
@@ -62,19 +62,22 @@
     LY_CHECK_ARG_RET(ctx, ctx, LY_EINVAL);
 
     if (search_dir) {
-        LY_CHECK_ERR_RET(access(search_dir, R_OK | X_OK),
-                         LOGERR(ctx, LY_ESYS, "Unable to use search directory \"%s\" (%s)", search_dir, strerror(errno)),
-                         LY_EINVAL);
-        LY_CHECK_ERR_RET(stat(search_dir, &st),
-                         LOGERR(ctx, LY_ESYS, "stat() failed for \"%s\" (%s)", search_dir, strerror(errno)),
-                         LY_ESYS);
-        LY_CHECK_ERR_RET(!S_ISDIR(st.st_mode),
-                         LOGERR(ctx, LY_ESYS, "Given search directory \"%s\" is not a directory.", search_dir),
-                         LY_EINVAL);
         new_dir = realpath(search_dir, NULL);
         LY_CHECK_ERR_RET(!new_dir,
-                         LOGERR(ctx, LY_ESYS, "realpath() call failed for \"%s\" (%s).", search_dir, strerror(errno)),
+                         LOGERR(ctx, LY_ESYS, "Unable to use search directory \"%s\" (%s).", search_dir, strerror(errno)),
+                         LY_EINVAL);
+        if (strcmp(search_dir, new_dir)) {
+            LOGVRB("Canonicalizing search directory string from \"%s\" to \"%s\".", search_dir, new_dir);
+        }
+        LY_CHECK_ERR_RET(access(new_dir, R_OK | X_OK),
+                         LOGERR(ctx, LY_ESYS, "Unable to fully access search directory \"%s\" (%s).", new_dir, strerror(errno)); free(new_dir),
+                         LY_EINVAL);
+        LY_CHECK_ERR_RET(stat(new_dir, &st),
+                         LOGERR(ctx, LY_ESYS, "stat() failed for \"%s\" (%s).", new_dir, strerror(errno)); free(new_dir),
                          LY_ESYS);
+        LY_CHECK_ERR_RET(!S_ISDIR(st.st_mode),
+                         LOGERR(ctx, LY_ESYS, "Given search directory \"%s\" is not a directory.", new_dir); free(new_dir),
+                         LY_EINVAL);
         /* avoid path duplication */
         for (u = 0; u < ctx->search_paths.count; ++u) {
             if (!strcmp(new_dir, ctx->search_paths.objs[u])) {
diff --git a/tests/src/test_context.c b/tests/src/test_context.c
index 624cf6f..2a3c302 100644
--- a/tests/src/test_context.c
+++ b/tests/src/test_context.c
@@ -109,10 +109,10 @@
     logbuf_assert("Given search directory \""TESTS_BIN"/src_context\" is not a directory.");
     /* not executable */
     assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(ctx, __FILE__));
-    logbuf_assert("Unable to use search directory \""__FILE__"\" (Permission denied)");
+    logbuf_assert("Unable to fully access search directory \""__FILE__"\" (Permission denied).");
     /* not existing */
     assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(ctx, "/nonexistingfile"));
-    logbuf_assert("Unable to use search directory \"/nonexistingfile\" (No such file or directory)");
+    logbuf_assert("Unable to use search directory \"/nonexistingfile\" (No such file or directory).");
 
     /* ly_set_add() fails */
     /* no change */
@@ -174,7 +174,7 @@
 
     /* test searchdir list in ly_ctx_new() */
     assert_int_equal(LY_EINVAL, ly_ctx_new("/nonexistingfile", 0, &ctx));
-    logbuf_assert("Unable to use search directory \"/nonexistingfile\" (No such file or directory)");
+    logbuf_assert("Unable to use search directory \"/nonexistingfile\" (No such file or directory).");
     assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_SRC":/home:/home:"TESTS_SRC, 0, &ctx));
     assert_int_equal(2, ctx->search_paths.count);
     assert_string_equal(TESTS_SRC, ctx->search_paths.objs[0]);