Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fallback implementation is used if preferred value of none #1255

Merged

Conversation

SoumyaRanjanPatnaik
Copy link
Contributor

Don't use fallback portal implementations in the following cases:

  • the preferred portals for an interface contains none
  • no preference is set for the interface but the default preference contains none

Fixes #1254

Copy link
Collaborator

@ebassi ebassi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

src/portal-impl.c Outdated Show resolved Hide resolved
src/portal-impl.c Outdated Show resolved Hide resolved
src/portal-impl.c Outdated Show resolved Hide resolved
src/portal-impl.c Outdated Show resolved Hide resolved
@SoumyaRanjanPatnaik
Copy link
Contributor Author

Fixed lint issues :)

@GreyXor
Copy link

GreyXor commented Jan 11, 2024

Hi, thanks for this PR. that would be nice to have this fix in the next release. That could fix sway+firefox idle inhibit https://gitlab.archlinux.org/archlinux/packaging/packages/sway/-/issues/2

@jp7677
Copy link

jp7677 commented Feb 9, 2024

Any chance to get this PR merged?
(That said, tests are failing, may be some additional work on that front is needed.)

This would fix the firefox-idle-inhibit issue not only for sway, but for other/all wlroots based compositors, labwc in my case.

@GeorgesStavracas
Copy link
Member

Not only tests must pass, but the commits have to be squashed, and the commit message must follow the pattern that other commits do.

@SoumyaRanjanPatnaik
Copy link
Contributor Author

@GeorgesStavracas The tests don't fail on my system. I can't figure out why they fail in CI.

$ meson test -C build

ninja: Entering directory `/home/soumyarp/git/xdg-desktop-portal/build'
[61/61] Linking target tests/limited-portals
 1/24 xdg-desktop-portal / testdb                                    OK              0.01s   3 subtests passed
 2/24 xdg-desktop-portal / test-doc-portal                           OK              0.10s   5 subtests passed
 3/24 xdg-desktop-portal:portals / test-portals-camera               OK              1.10s   1 subtests passed
 4/24 xdg-desktop-portal:portals / test-portals-background           OK              1.10s   1 subtests passed
 5/24 xdg-desktop-portal:portals / test-portals-account              OK              1.11s   1 subtests passed
 6/24 xdg-desktop-portal:portals / test-portals-inhibit              OK              1.11s   1 subtests passed
 7/24 xdg-desktop-portal:portals / test-portals-notification         OK              1.10s   1 subtests passed
 8/24 xdg-desktop-portal:portals / test-portals-location             SKIP            1.11s   0 subtests passed
 9/24 xdg-desktop-portal:portals / test-portals-email                OK              1.11s   1 subtests passed
10/24 xdg-desktop-portal:portals / test-portals-color                SKIP            1.12s
11/24 xdg-desktop-portal:portals / test-portals-openfile             SKIP            1.10s
12/24 xdg-desktop-portal:portals / test-portals-prepareprint         SKIP            1.11s
13/24 xdg-desktop-portal:portals / test-portals-savefile             SKIP            1.10s
14/24 xdg-desktop-portal:portals / test-portals-openuri              OK              1.12s   1 subtests passed
15/24 xdg-desktop-portal:portals / test-portals-print                OK              1.11s   1 subtests passed
16/24 xdg-desktop-portal:portals / test-portals-screenshot           OK              1.10s   1 subtests passed
17/24 xdg-desktop-portal:portals / test-portals-settings             OK              1.09s   1 subtests passed
18/24 xdg-desktop-portal:portals / test-portals-trash                OK              1.09s   1 subtests passed
19/24 xdg-desktop-portal:portals / limited-portals-openfile          SKIP            1.05s
20/24 xdg-desktop-portal:portals / limited-portals-savefile          SKIP            1.05s
21/24 xdg-desktop-portal:portals / test-portals-wallpaper            OK              1.07s   1 subtests passed
22/24 xdg-desktop-portal / test-permission-store                     OK              0.08s   14 subtests passed
23/24 xdg-desktop-portal / test-xdp-utils                            OK              0.01s   6 subtests passed
24/24 xdg-desktop-portal / test-xdp-method-info                      OK              0.00s   2 subtests passed

Ok:                 17  
Expected Fail:      0   
Fail:               0   
Unexpected Pass:    0   
Skipped:            7   
Timeout:            0   

Full log written to /home/soumyarp/git/xdg-desktop-portal/build/meson-logs/testlog.txt

@GeorgesStavracas
Copy link
Member

Maybe a simple rebase would be sufficient? Please make sure to update the commit message

@SoumyaRanjanPatnaik
Copy link
Contributor Author

Squashed the commits and rebased on top of main. Hope the tests check out.

@jp7677
Copy link

jp7677 commented Feb 9, 2024

@SoumyaRanjanPatnaik CI test failures shows:

 19/30 xdg-desktop-portal:portals / limited-portals-openfile           ERROR            0.28s   killed by signal 6 SIGABRT
>>> G_TEST_SRCDIR=/src/tests MALLOC_PERTURB_=229 XDG_CURRENT_DESKTOP=limited XDP_UNINSTALLED=1 XDG_DATA_DIRS=/src/builddir/tests/share G_DEBUG=gc-friendly G_TEST_BUILDDIR=/src/builddir/tests /src/builddir/tests/limited-portals --verbose --keep-going --tap -p /limited/openfile

[20-21/30] 🌒 xdg-desktop-portal:portals / limited-portals-savefile                    0/ 30s
20/30 xdg-desktop-portal:portals / limited-portals-savefile           ERROR            0.25s   killed by signal 6 SIGABRT
>>> G_TEST_SRCDIR=/src/tests XDG_CURRENT_DESKTOP=limited XDP_UNINSTALLED=1 XDG_DATA_DIRS=/src/builddir/tests/share G_DEBUG=gc-friendly G_TEST_BUILDDIR=/src/builddir/tests MALLOC_PERTURB_=217 /src/builddir/tests/limited-portals --verbose --keep-going --tap -p /limited/savefile

You don't hit those errors locally because your test setup skipped those tests. From your logs:

19/24 xdg-desktop-portal:portals / limited-portals-openfile          SKIP            1.05s
20/24 xdg-desktop-portal:portals / limited-portals-savefile          SKIP            1.05s

@SoumyaRanjanPatnaik
Copy link
Contributor Author

I don't want to be that guy, but either failing tests are wrong. Either that or the FileChooser interface has a bug. Let me elaborate...

  • Previously, with none not working, the limited-portals-openfile and limited-portals-savefile tests probably called an interface that is not enabled in the limited-portals.conf file.
  • This patch caused none to function correctly, which caused the calls to the disabled interface to fail.
  • Setting the default interface to limited in limited-portals.conf causes the failing test cases to pass

I have yet to investigate which interfaces are being called in these tests. The naive fix is just to set the default interface to limited, which I don't think might be a very good idea.

[preferred]
- default=none
+ default=limited
org.freedesktop.impl.portal.Account=limited
org.freedesktop.impl.portal.FileChooser=limited
org.freedesktop.impl.portal.Lockdown=limited
org.freedesktop.impl.portal.Settings=limited

The alternative is to either figure out if the disabled interfaces are invoked and remove occurrences of these invocations, or to fix the FileChooser interface to not fail when the default backend is none.

Since fixing tests or the FileChooser interface is unrelated to this PR, it is probably better to file a separate issue.

@SoumyaRanjanPatnaik
Copy link
Contributor Author

SoumyaRanjanPatnaik commented Feb 9, 2024

@jp7677 thanks for pointing out the failing tests were skipped on my system. It turns out I had to enable the installed-tests feature for those tests to not be skipped on my system. It might be a good idea to add this to the contributor documentation.

This is how I ran the tests:

meson setup . build --prefix /usr -Dinstalled-tests=true
meson test -C build

@jp7677
Copy link

jp7677 commented Feb 10, 2024

Hi @SoumyaRanjanPatnaik I'm looking (without having former experience with this project) at your patch and the tests.

Your patch says:

static gboolean
portal_interface_prefers_none (const char *interface)
{
  const PortalInterface *iface = find_matching_iface_config (interface);

  if (iface != NULL && g_strv_contains ((const char * const *) iface->portals, "none"))
    {
      g_debug ("Found 'none' in configuration for %s", iface->dbus_name);
      return TRUE;
    }

  if (config != NULL && g_strv_contains ((const char * const *) config->default_portal->portals, "none"))
      return TRUE;

  return FALSE;
}

As far as I'm reading this, it translates to: disable this interface when the interface itself is disabled (org.freedesktop.impl.portal.FileChooser=none) or no fallback is set (default=none).

Looking at the test configuration:

[preferred]
default=none
org.freedesktop.impl.portal.Account=limited
org.freedesktop.impl.portal.FileChooser=limited
org.freedesktop.impl.portal.Lockdown=limited
org.freedesktop.impl.portal.Settings=limited

this means that all interfaces are disabled because one of the two conditions (the second one) is true. I think (not sure though) that the second if statement should only return true when that specific interface is not mentioned in the configuration file (or something similar). So I think the test failure is justified.

Edit: May be something like this is needed (essentially adding iface == NULL as condition to your version), the tests are good with this change and the test debug output shows expected output when I'm playing with 'none':

diff --git a/src/portal-impl.c b/src/portal-impl.c
index 7086f55..1c6e6b3 100644
--- a/src/portal-impl.c
+++ b/src/portal-impl.c
@@ -516,8 +516,11 @@ portal_interface_prefers_none (const char *interface)
       return TRUE;
     }
 
-  if (config != NULL && g_strv_contains ((const char * const *) config->default_portal->portals, "none"))
-    return TRUE;
+  if (iface == NULL && config != NULL && g_strv_contains ((const char * const *) config->default_portal->portals, "none"))
+    {
+      g_debug ("No configuration found for %s and default is 'none'", interface);
+      return TRUE;
+    }
 
   return FALSE;
 }

@SoumyaRanjanPatnaik
Copy link
Contributor Author

SoumyaRanjanPatnaik commented Feb 11, 2024

As far as I'm reading this, it translates to: disable this interface when the interface itself is disabled (org.freedesktop.impl.portal.FileChooser=none) or no fallback is set (default=none).

@jp7677 Thanks for correctly pointing this out. I prematurely blamed the tests (really stupid of me 😢). Tests seem to pass after updating portal_interface_prefers_none with the following.

static gboolean
portal_default_prefers_none ()
{
  if (config != NULL && g_strv_contains ((const char * const *) config->default_portal->portals, "none"))
    {
      g_debug ("Found 'none' in configuration for default");
      return TRUE;
    }

  return FALSE;
}

static gboolean
portal_interface_prefers_none (const char *interface)
{
  const PortalInterface *iface = find_matching_iface_config (interface);
  if (iface == NULL)
    return portal_default_prefers_none();

  if (g_strv_contains ((const char * const *) iface->portals, "none"))
    {
      g_debug ("Found 'none' in configuration for %s", iface->dbus_name);
      return TRUE;
    }

  return FALSE;
}

@jp7677
Copy link

jp7677 commented Feb 11, 2024

@SoumyaRanjanPatnaik no worries, I’m happy to help to bring this forward. Thanks a lot for your work in the first place to address this issue!
(I guess #1282 can be closed now ;) )

@jp7677
Copy link

jp7677 commented Feb 23, 2024

@GeorgesStavracas @ebassi is there anything left that needs to be done for this commit to get in? FWIW, I'm running this commit on top of xdg-desktop-portal-1.18.2 together with labwc for more than a week now and it works as intended without noticing any negative side effects.

src/portal-impl.c Outdated Show resolved Hide resolved
src/portal-impl.c Outdated Show resolved Hide resolved
src/portal-impl.c Outdated Show resolved Hide resolved
Don't use fallback portal implementations in the following cases:
- the preferred portals for an interface contains `none`
- no preference is set for the interface but the default preference contains `none`
@SoumyaRanjanPatnaik
Copy link
Contributor Author

@GeorgesStavracas Thanks for the review. Pushed the changes.

@SoumyaRanjanPatnaik
Copy link
Contributor Author

SoumyaRanjanPatnaik commented Feb 23, 2024

Please follow the project code style:

Just curious, does this project have any documentation or formatter for enforcing the coding style? I searched for some documentation on code but found no leads in this regard.

@jp7677
Copy link

jp7677 commented Mar 8, 2024

@ebassi @GeorgesStavracas gentle ping...

@GeorgesStavracas GeorgesStavracas added this to the 1.20 milestone Mar 8, 2024
@GeorgesStavracas GeorgesStavracas added this pull request to the merge queue Mar 8, 2024
Merged via the queue into flatpak:main with commit 1394bb2 Mar 8, 2024
4 checks passed
@GeorgesStavracas
Copy link
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug config Issues with the portal configuration mechanism
Projects
Status: Triaged
Development

Successfully merging this pull request may close these issues.

UseIn fallbck is used even if preference is set to none for interfaces within portals.conf file
5 participants