PengZheng commented on code in PR #476:
URL: https://github.com/apache/celix/pull/476#discussion_r1114336712


##########
libs/framework/include/celix/Bundle.h:
##########
@@ -74,6 +80,43 @@ namespace celix {
         }
 #endif
 
+       /**
+        * @brief Return a use-able entry path for the provided relative path 
to a bundle persistent storage.
+        *
+        * For example if there is a resource entry in the bundle persistent 
storage at path 'resources/counters.txt` this call
+        * will return a relative path to entry in the bundle persistent 
storage.
+        * .cache/bundle5/storage/resources/counters.txt
+        *
+        * A provided path is always relative to the bundle persistent storage 
root and can start with a "/".
+        * A provided path NULL, "", "." or "/" indicates the root of this 
bundle cache store.
+        *
+        * The returned entry path should can be treated as read-write.
+        *
+        * @param path The relative path to a bundle persistent storage entry.
+        * @return The use-able entry path or an empty string if the entry is 
not found.
+        */
+#if __cplusplus >= 201703L //C++17 or higher
+        [[nodiscard]] std::string getDataFile(std::string_view path) const {
+            std::string result{};
+            char* entry = celix_bundle_getDataFile(cBnd.get(), path.data());

Review Comment:
   `path.data` is not guaranteed to be null-terminated, thus I think this 
method is flawed.
   
   https://en.cppreference.com/w/cpp/string/basic_string_view/data
   
   ```C++
   #include <iostream>
   #include <cstring>
   #include <cwchar>
   #include <string>
   #include <string_view>
   int main()
   {
       std::wstring_view wcstr_v = L"xyzzy";
       std::cout << std::wcslen(wcstr_v.data()) << '\n';
       // OK: the underlying character array is null-terminated
    
       char array[3] = {'B', 'a', 'r'};
       std::string_view array_v(array, sizeof array);
       // std::cout << std::strlen(array_v.data()) << '\n';
       // error: the underlying character array is not null-terminated
    
       std::string str(array_v.data(), array_v.size()); // OK
       std::cout << std::strlen(str.data()) << '\n';
       // OK: the underlying character array of a std::string is always 
null-terminated
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to