After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 740738 - [th/keyfile-write-connection-bgo740738] review: renaming a connection doesn't result in renaming the file
[th/keyfile-write-connection-bgo740738] review: renaming a connection doesn't...
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: NetworkManager maintainer(s)
NetworkManager maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2014-11-26 10:03 UTC by Pavel Simerda
Modified: 2015-07-24 09:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
keyfile: rename files when changing connection id (1.98 KB, patch)
2014-11-28 17:41 UTC, Thomas Haller
none Details | Review
keyfile: rename files when changing connection id (2.90 KB, patch)
2014-11-30 16:40 UTC, Thomas Haller
none Details | Review
keyfile: rename files when changing connection id (2.95 KB, patch)
2014-12-01 16:33 UTC, Thomas Haller
none Details | Review
keyfile: retry finding a suitable filename in writer() (2.62 KB, patch)
2014-12-01 16:34 UTC, Thomas Haller
none Details | Review
keyfile: retry harder finding a suitable filename in writer() (2.89 KB, patch)
2015-01-09 15:17 UTC, Thomas Haller
committed Details | Review
keyfile: rename files when changing connection id (1.63 KB, patch)
2015-01-09 15:17 UTC, Thomas Haller
rejected Details | Review

Description Pavel Simerda 2014-11-26 10:03:42 UTC
I used nm-connection-editor (that shouldn't make any change, right?) to create and then rename a connection. NetworkManager created the connection file in /etc/NetworkManager/system-connections with the correct name initially, but didn't rename the file to the new name. That way the administrator can't easily find the file and other issues may possibly occur.
Comment 1 Thomas Haller 2014-11-26 12:11:01 UTC
> I used nm-connection-editor (that shouldn't make any change, right?)
(-- I think, that makes no difference.)


I agree, keyfile should rename the files if the connection.id changes.

-- As long, as no such file already exists. If a file already exists, we probably should perform no renaming at all. Otherwise it'd becomes a deep rabbit hole of renaming.
Comment 2 Pavel Simerda 2014-11-27 12:07:17 UTC
I would actually be happy if we could enforce the identity of the name and ID but I don't know whether that's feasible. In that case all files would be named correctly no id would be needed (if configured by hand) and any renaming would be possible in a consistent state, in an inconsistent one, you could simply refuse to save the connection under the new name (looking at it from the perspective of nm-connection-editor).
Comment 3 Dan Winship 2014-11-27 14:00:42 UTC
We don't (currently) enforce uniqueness of connection IDs, so we couldn't enforce a 1-1 mapping of ID to name.
Comment 4 Pavel Simerda 2014-11-28 13:07:02 UTC
OK, then treat the bug report just as a suggestion and change it to whatever is the best we can do or close it.
Comment 5 Thomas Haller 2014-11-28 17:41:38 UTC
Created attachment 291740 [details] [review]
keyfile: rename files when changing connection id

Only take this endeavor when no conflicting keyfile
exists. Otherwise, keep the old filename.

If the desired name exists, we also try ID-UUID as second
guess.
Comment 6 Thomas Haller 2014-11-30 16:40:31 UTC
Created attachment 291838 [details] [review]
keyfile: rename files when changing connection id

Only take this endeavor when no conflicting keyfile
exists. Otherwise, keep the old filename.

If the desired name exists, we also try ID-UUID as second
guess.

This basically undoes commit eeb19fe2164ab97d84c0d46b978e91768cdb1878,
which was added to fix the related bug #682570.
Comment 7 Thomas Haller 2014-11-30 16:46:05 UTC
(In reply to comment #6)

Note that in bug 682570 the main issue was that connections were duplicated when changing the connection ID. That is already fixed by calling unlink(existing_path).

But patch eeb19fe2164ab97d84c0d46b978e91768cdb1878 also disables the renaming of keyfiles. Let's undo that patch.
Comment 8 Dan Williams 2014-12-01 15:44:23 UTC
(In reply to comment #6)
> Created an attachment (id=291838) [details] [review]
> keyfile: rename files when changing connection id
> 
> Only take this endeavor when no conflicting keyfile
> exists. Otherwise, keep the old filename.
> 
> If the desired name exists, we also try ID-UUID as second
> guess.
> 
> This basically undoes commit eeb19fe2164ab97d84c0d46b978e91768cdb1878,
> which was added to fix the related bug #682570.

existing_path will never be outside of keyfile_dir since it is always based on keyfile_dir.  That can just be enforced with g_return_val_if_fail() or even g_assert(), though we have to be careful of testcases here.  So we don't need that part of the check in the first hunk of the patch.

existing_path should only be used as a fallback, since it's just the cached path of the last place the file was saved. If we always rename to the current ID instead of preferring existing_path, then the only time we use existing_path is if all renaming efforts failed.  So we never would "prefer" existing_path at all since it would be used as a last resort.
Comment 9 Thomas Haller 2014-12-01 16:33:56 UTC
Created attachment 291936 [details] [review]
keyfile: rename files when changing connection id

Only take this endeavor when no conflicting keyfile
exists. Otherwise, keep the old filename.

If the desired name exists, we also try ID-UUID as second
guess.

This basically undoes commit eeb19fe2164ab97d84c0d46b978e91768cdb1878,
which was added to fix the related bug #682570.
Comment 10 Thomas Haller 2014-12-01 16:34:03 UTC
Created attachment 291937 [details] [review]
keyfile: retry finding a suitable filename in writer()

Try harder to find a suitable filename by appending a counter
to the name.
Comment 11 Dan Williams 2014-12-08 16:19:36 UTC
jklimes, any comment about these patches WRT https://bugzilla.gnome.org/show_bug.cgi?id=682570#c2 ?  Bug 682570 and this bug are requesting exactly opposite behavior WRT file name matching the ID.
Comment 12 Jiri Klimes 2015-01-09 11:37:23 UTC
(In reply to comment #11)
> jklimes, any comment about these patches WRT
> https://bugzilla.gnome.org/show_bug.cgi?id=682570#c2 ?  Bug 682570 and this bug
> are requesting exactly opposite behavior WRT file name matching the ID.

I still prefer not renaming files if ID changes.
It seems nice if the connection name and the file name match. On the other hand I see file name changes quite unfriendly, because I would expect that the file name is not mysteriously changed or renamed (namely if it is created manually).
Comment 13 Dan Winship 2015-01-09 13:58:42 UTC
On the other other hand, I tend to assume that if I have a connection named "foobar", that it's going to be in /etc/sysconfig/network-scripts/ifcfg-foobar, and I find it confusing when it's not.

How about if we rename the file if its old filename matches its old ID, but keep the old filename otherwise?
Comment 14 Thomas Haller 2015-01-09 14:22:43 UTC
(In reply to comment #12)
> (In reply to comment #11)
> > jklimes, any comment about these patches WRT
> > https://bugzilla.gnome.org/show_bug.cgi?id=682570#c2 ?  Bug 682570 and this bug
> > are requesting exactly opposite behavior WRT file name matching the ID.
> 
> I still prefer not renaming files if ID changes.
> It seems nice if the connection name and the file name match. On the other hand
> I see file name changes quite unfriendly, because I would expect that the file
> name is not mysteriously changed or renamed (namely if it is created manually).

Even with this change we would not randomly rename files. They get only renamed during a save. I would very much expected that your file changes in that case. Including a rename.

Note that this was the original behavior it got changed: https://bugzilla.gnome.org/show_bug.cgi?id=682570#c2 .

This RFE requests again renaming and undo that change. I would agree with that later option.


(In reply to comment #13)
> On the other other hand, I tend to assume that if I have a connection named
> "foobar", that it's going to be in /etc/sysconfig/network-scripts/ifcfg-foobar,
> and I find it confusing when it's not.

(btw. these patches are about keyfiles. But the same reasoning applies)

> How about if we rename the file if its old filename matches its old ID, but
> keep the old filename otherwise?

But inside _internal_write_connection(), where the decision is made, the original connection-id is not easily at hand. And I would find this behavior inconsistent. I would either always or never rename.



But yeah... how do we agree?
Comment 15 Thomas Haller 2015-01-09 15:17:38 UTC
Created attachment 294161 [details] [review]
keyfile: retry harder finding a suitable filename in writer()

Try harder to find a suitable filename by appending a counter
to the name.
Comment 16 Thomas Haller 2015-01-09 15:17:45 UTC
Created attachment 294162 [details] [review]
keyfile: rename files when changing connection id

Only take this endeavor when no conflicting keyfile
exists. Otherwise, keep the old filename.

If the desired name exists, we also try ID-UUID as second
guess.

This basically undoes commit eeb19fe2164ab97d84c0d46b978e91768cdb1878,
which was added to fix the related bug #682570.
Comment 17 Thomas Haller 2015-01-09 15:21:19 UTC
Obsoleted previous patches.

The first (attachment 294161 [details] [review]) does not change any behavior regarding rename or not. It only adds retrying to find a suitable file name.
I think this one can be commited any case.


The second is a trivial patch, whether we want to rename the file on rename or not.
Comment 18 Thomas Haller 2015-01-12 11:25:13 UTC
Comment on attachment 294161 [details] [review]
keyfile: retry harder finding a suitable filename in writer()

http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=3b1c5ee0fde05f2d7d786d474591f4d23d64284a
Comment 19 Thomas Haller 2015-01-12 11:27:15 UTC
Commited attachment 294161 [details] [review].

attachment 294162 [details] [review] is left undecided, and the question is *what* to do and whether to rename the file -- the "how" is trivial.
Comment 20 Dan Williams 2015-01-12 23:09:15 UTC
(In reply to comment #13)
> On the other other hand, I tend to assume that if I have a connection named
> "foobar", that it's going to be in /etc/sysconfig/network-scripts/ifcfg-foobar,
> and I find it confusing when it's not.

My feeling is that if you explicitly rename the connection through NM (which most people won't do, and most people on servers won't do either), then yeah, I think it should get renamed.  We should obviously make sure it only happens when explicitly requested, of course (eg, NM should *not* rename when it reads a connection off disk where the ID != filename), and these patches do that AFAICT.

> How about if we rename the file if its old filename matches its old ID, but
> keep the old filename otherwise?

I would agree with that, it sounds like a nice compromise.
Comment 21 Thomas Haller 2015-07-17 09:21:16 UTC
New branch th/keyfile-write-connection-bgo740738 for review.

- it adds a configuration option keyfile.rename-file which allows the user to configure that keyfile plugin will rename files.

- also do some cleanup, fix a memleak, and improve logging and error messages.
Comment 22 Beniamino Galvani 2015-07-17 13:13:00 UTC
> keyfile: add info logging when updating connection

+ nm_log_info (LOGD_SETTINGS, "keyfile: update "NM_KEYFILE_CONNECTION_LOG_FMT" and persistate connection",

persist connection?

IMO always renaming the file when keyfile.rename-file=yes even if the old filename is different from old ID makes sense. The branch looks good to me.
Comment 23 Thomas Haller 2015-07-17 13:57:36 UTC
(In reply to Beniamino Galvani from comment #22)
> > keyfile: add info logging when updating connection
> 
> + nm_log_info (LOGD_SETTINGS, "keyfile: update
> "NM_KEYFILE_CONNECTION_LOG_FMT" and persistate connection",
> 
> persist connection?
> 
> IMO always renaming the file when keyfile.rename-file=yes even if the old
> filename is different from old ID makes sense. The branch looks good to me.

Fixed && repushed.
Comment 24 Dan Williams 2015-07-17 23:18:36 UTC
> keyfile: add keyfile.rename-file config option

Hmm, I don't think we need a config option for this.  Was something not easily implemented about comment #20?

The rest of the patches look OK though.
Comment 25 Thomas Haller 2015-07-19 10:36:42 UTC
(In reply to Dan Williams from comment #24)
> > keyfile: add keyfile.rename-file config option
> 
> Hmm, I don't think we need a config option for this.  Was something not
> easily implemented about comment #20?

I moved that commit as last, and added one fixup! commit.

Repushed.

How is it now?
Comment 26 Dan Williams 2015-07-23 20:12:19 UTC
Yeah, I like that a lot better.  LGTM.
Comment 27 Thomas Haller 2015-07-24 09:34:44 UTC
merged to master as http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=be5f85ff637204e126346f71576fce53837405ac


Closing BZ as fixed, because if you now modify the connection ID via D-Bus, the keyfile will be renamed (this only works for keyfile plugin).