[Github-comments] [geany/geany] use relative path in project file (#2667)

elextr notifications at xxxxx
Thu Nov 19 22:45:22 UTC 2020


@elextr requested changes on this pull request.

Not reviewed in detail yet.

This capability needs to be documented in the manual, including downsides and risks such as accidentally storing all files you have open in git and broadcasting that to the world.  New settings not documented either.

>  
 	if (ft == NULL) /* can happen when saving a new file when quitting */
 		ft = filetypes[GEANY_FILETYPES_NONE];
 
-	locale_filename = utils_get_locale_from_utf8(doc->file_name);
+	/* project_root_folder contain a path only if the project use relative path */
+	if(project_root_folder){
+		file_root_folder = g_file_new_for_path(project_root_folder);
+		file_doc = g_file_new_for_path(doc->file_name);
+		relative_filename = g_file_get_relative_path(file_root_folder, file_doc);
+		if(relative_filename){
+			/* Append './' so we know it is a relative filename */
+			doc_filename = g_strconcat("./",relative_filename, NULL);

As `relative_filename` is in locale encoding technically you don't know if `./` is properly encoded to prepend (not append)

>  
 	if (ft == NULL) /* can happen when saving a new file when quitting */
 		ft = filetypes[GEANY_FILETYPES_NONE];
 
-	locale_filename = utils_get_locale_from_utf8(doc->file_name);
+	/* project_root_folder contain a path only if the project use relative path */
+	if(project_root_folder){
+		file_root_folder = g_file_new_for_path(project_root_folder);
+		file_doc = g_file_new_for_path(doc->file_name);
+		relative_filename = g_file_get_relative_path(file_root_folder, file_doc);
+		if(relative_filename){
+			/* Append './' so we know it is a relative filename */
+			doc_filename = g_strconcat("./",relative_filename, NULL);
+		}else{
+			doc_filename = g_strconcat(doc->file_name, NULL);

Why are you concating nothing?

> @@ -611,6 +618,10 @@ static void show_project_properties(gboolean show_build)
 	gtk_entry_set_text(GTK_ENTRY(e.patterns), entry_text);
 	g_free(entry_text);
 
+	gtk_toggle_button_set_active(
+		GTK_TOGGLE_BUTTON(ui_lookup_widget(e.dialog, "checkbutton_project_dialog_file_relative")),

Didn't you lookup this widget above? Can't you use that pointer.

> @@ -1218,6 +1242,21 @@ static gboolean open_session_file(gchar **tmp, guint len)
 	unescaped_filename = g_uri_unescape_string(tmp[7], NULL);
 	locale_filename = utils_get_locale_from_utf8(unescaped_filename);
 
+	/* is the locale_filename absolute or relative ? */
+	if(g_path_is_absolute(locale_filename) && root_folder)
+	{
+		geany_debug("Absolute path");
+	}
+	else
+	{
+		geany_debug("Relative path %s, root folder %s", locale_filename, root_folder);
+		gchar *absolute_path;
+		absolute_path = g_strconcat(root_folder, &(locale_filename[1]), NULL);

What if the path is relative, but `root_folder` is null?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/2667#pullrequestreview-534908936
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20201119/250353ba/attachment-0001.htm>


More information about the Github-comments mailing list