Saving a file changes the file's owner.

24 views
Skip to first unread message

joe.s....@gmail.com

unread,
Mar 2, 2018, 10:48:35 PM3/2/18
to Tilde text editor
It looks like the file save operation removes the file then writes a new file with the same name.  This means that whenever you save a file you become the file's owner even if you hadn't been the file's owner when you started editing the file.

E.g. Let's say you are not the file's owner but you are one of the group in the file's group.  Now the group has write permission on the file so you would be able to open the file with Tilde text editor.  If you modify and save the file, then you become that file's owner.

Is there a way to modify and save a file without becoming that file's new owner?  Is there a configuration change to preserve file ownership when saving a file?

Gertjan Halkes

unread,
Mar 5, 2018, 3:03:40 AM3/5/18
to Tilde text editor
Hi Joe,

Sorry for the late response, I was out for the weekend.

This is a bug in Tilde, which is the result of Tilde attempting to be extremely careful at not corrupting the file. To achieve this, it first writes the intended file to a temporary file, and then renames the temporary file over the existing one. When I coded this I unfortunately did not properly take the ownership of the file into account. I've filed a bug on the github bugtracker for tilde.

Cheers,
Gertjan

joe.s....@gmail.com

unread,
Mar 7, 2018, 10:19:47 AM3/7/18
to Tilde text editor
Hi Gertjan,

Thx for your reply.  Yes I'd consider it a design trade-off.  I'm a storage driver guy by trade and the double buffered write is usually the better design.  But there's no way, no how Linux will let one (non-root) user create a file and make it owned by another user.  Not by "chown", "cp -p", "mv -p".  Nothing!

So the solution you propose in the bug citation seems to be best.  Duplicate old file (even though the duplicate is owned by the current user), check free space, character set, check anything else that could make a write fail, and if all is OK then overwrite the existing file that then retains that existing owner.

You must be working very hard on Tilde, and how wonderful it is.  Would you like me to attempt to make this change?

Thx,  Joe

Gertjan Halkes

unread,
Mar 8, 2018, 4:00:42 AM3/8/18
to Tilde text editor
Hi Joe,

If you would like to try to implement this, I'd very much welcome the help. My main focus currently is on refreshing the code, as it was written pre-C++11, and with less experience as a C++ coder. I must warn you though, the code that deals with the writing of files is rather impenetrable, as it tries to implement the saving in a way that it can be restarted after asking the user for confirmation (like whether it is OK to overwrite a file).

Maybe we can take it in steps: first add the code that attempts the character conversion, and determines the final size of the file. I think that would already be helpful, as Tilde can then ask the user whether they want a different encoding or deal with any impossible conversions in another way.

Best regards,
Gertjan Halkes

Joseph Cavallo

unread,
Apr 26, 2018, 4:23:30 PM4/26/18
to Gertjan Halkes, Tilde text editor
Hi Gertjan,

Wow I didn’t even know clang was getting traction.  I’d rather stay with gcc.  I put "CC = gcc" in the Makefile, then I tried "COMPILER = gcc".  Neither worked.  Both said something about libtools can’t find clang.  Do you know how to compile your project with gcc where I’d make libtools use gcc as well.

Thx,  Joe
 

-- 
You received this message because you are subscribed to a topic in the Google Groups "Tilde text editor" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tilde-text-edi...@googlegroups.com.
To post to this group, send email to tilde-te...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tilde-text-editor/26d2cb4c-06a6-49c0-9f43-dcaa7060169f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gertjan Halkes

unread,
Apr 27, 2018, 8:56:17 AM4/27/18
to Tilde text editor
Hi Joe,

It should work with passing COMPILER=gcc. This is how I sometimes compile it with gcc, to test. Not sure why it is not working for you. It may be that there is some step where it inadvertently passes "clang" instead of$(CC), or something like that. You can use VERBOSE=1 to show the command lines of the compilation commands.

Can you perhaps provide the full error message, and some information about the environment you are running this in? (E.g. the linux distro and version, and anything else that may seem relevant?)

Cheers,
Gertjan
To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsub...@googlegroups.com.
To post to this group, send email to tilde-text-editor@googlegroups.com.

Joseph Cavallo

unread,
Apr 30, 2018, 4:21:53 PM4/30/18
to Gertjan Halkes, Tilde text editor
Hi Gertjan,

Here's a screenshot.

I don't think the Makefile is being used b/c I tried smudging it by typing "FHSJKASDVHJ" into it and that did not change the result.  When I can get down to the programming is when I start having fun.  :)

--Joe


To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsubscrib...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Tilde text editor" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsubscribe@googlegroups.com.

To post to this group, send email to tilde-text-editor@googlegroups.com.
tilde_compile.jpeg

Gertjan Halkes

unread,
Apr 30, 2018, 5:16:50 PM4/30/18
to Tilde text editor
Hi Joe,

Ah, I see where the problem is. You are right, that Makefile isn't used in the build. What you want is to add the COMPILER=gcc setting to the build command line like so:

./t3shared/doall --skip-non-source --stop-on-error make -C src COMPILER=gcc

Let me know if that doesn't work.

Cheers,
Gertjan
To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsub...@googlegroups.com.

Joseph Cavallo

unread,
Apr 30, 2018, 5:57:17 PM4/30/18
to Gertjan Halkes, Tilde text editor
OK I got pretty far now.  Now I got this error:

[CXXLT] colorscheme.cc
In file included from colorscheme.h:21:0,
                 from colorscheme.cc:14:
../../t3shared/../t3shared/include/t3window/window.h: In constructor ‘t3_window::window_t::window_t(t3_window::window_t&&)’:
../../t3shared/../t3shared/include/t3window/window.h:131:40: error: ‘move’ is not a member of ‘std’
   window_t(window_t &&other) { *this = std::move(other); }
                                        ^
../../makesys/rules.mk:295: recipe for target '.objects/colorscheme.lo' failed
make: *** [.objects/colorscheme.lo] Error 1
make: Leaving directory '/home/joe/jstorage/source/tilde/t3widget/src'


I have to admit that I am having trouble getting my source to compile with c++14.  I'm doing a different project in Netbeans that keeps using c++199711 no matter what I do.  It is possible that this build is also suffering from that issue.  Do I need to specify "-std=c++14" somewhere?


To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsubscrib...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Tilde text editor" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsubscribe@googlegroups.com.
To post to this group, send email to tilde-text-editor@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tilde-text-editor/a0bdea56-08f4-45fc-813f-b53d11326d9b%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Tilde text editor" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsubscribe@googlegroups.com.
To post to this group, send email to tilde-text-editor@googlegroups.com.

Gertjan Halkes

unread,
May 1, 2018, 2:00:50 AM5/1/18
to Tilde text editor
Given that it attempts to compile that piece of the code, it is compiling with C++11 mode on. However, the code didn't include the <utility> header, which is officially required by the C++ standard for std::move. I guess the standard library on my machine somehow already includes that with every path that includes this file, but that is of course not necessarily the case. I fixed the code to explicitly include it now.

Cheers,
Gertjan
To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsub...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Tilde text editor" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsubscribe@googlegroups.com.
To post to this group, send email to tilde-text-editor@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tilde-text-editor/a0bdea56-08f4-45fc-813f-b53d11326d9b%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Joseph Cavallo

unread,
May 2, 2018, 11:31:45 AM5/2/18
to Gertjan Halkes, Tilde text editor
Hi Gertjan,

OK I've compiled it.  Now that the fun has started let me see what I can do.

Thx,  Joe


To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsubscrib...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Tilde text editor" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsubscribe@googlegroups.com.
To post to this group, send email to tilde-text-editor@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tilde-text-editor/a0bdea56-08f4-45fc-813f-b53d11326d9b%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Tilde text editor" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsubscribe@googlegroups.com.
To post to this group, send email to tilde-text-editor@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tilde-text-editor/42adf1b3-194a-4694-95bc-e90d42e70631%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Tilde text editor" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsubscribe@googlegroups.com.
To post to this group, send email to tilde-text-editor@googlegroups.com.

Joseph Cavallo

unread,
Jun 20, 2018, 4:29:08 PM6/20/18
to Gertjan Halkes, Tilde text editor
Hi Gertjan,

Sorry I have been very busy interviewing for jobs and setting up some infrastructure for seeking freelance jobs.

I came back to Tilde just today.  I noticed you checked in a lot of changes.  Did you end up fixing that issue we had discussed about changing the file owner to the one editing the file? 

Anyway, now it's back to only compiling with clang.  I get this error again:

make: Entering directory '/home/joe/jstorage/source/tilde/transcript/src'
[CCLT] state_table_converter.c
/usr/bin/libtool: line 1766: clang: command not found
../../makesys/rules.mk:265: recipe for target '.objects/state_table_converter.lo' failed
make: *** [.objects/state_table_converter.lo] Error 1
make: Leaving directory '/home/joe/jstorage/source/tilde/



Gertjan Halkes

unread,
Jun 21, 2018, 4:31:17 PM6/21/18
to Tilde text editor
Hi Joe,

Thanks for letting me know.

I have not worked on the issue yet, as I have been busy working on modernizing the libt3widget API.

As for the clang compilation: are you passing COMPILER=gcc? It looks like it is attempting to compile libtranscript, which is the first thing it should be compiling.

Cheers,
Gertjan
To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsub...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Tilde text editor" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsubscribe@googlegroups.com.
To post to this group, send email to tilde-text-editor@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tilde-text-editor/a0bdea56-08f4-45fc-813f-b53d11326d9b%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Tilde text editor" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsubscribe@googlegroups.com.
To post to this group, send email to tilde-text-editor@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tilde-text-editor/42adf1b3-194a-4694-95bc-e90d42e70631%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Joseph Cavallo

unread,
Jul 31, 2018, 5:03:21 PM7/31/18
to Gertjan Halkes, Tilde text editor
Hi Gertjan,

I finally found time to work on this.  You already had the possibility to skip the double buffering if the attempt to create a new file failed.  Have a look at this from "filebuffer.cc".

          /* Attempt to create a temporary file. If this fails, just write the file
             directly. The latter has some risk (e.g. file truncation due to full disk,
             or corruption due to computer crashes), but these are so small that it is
             worth permitting this if we can't create the temporary file. */
          if ((state->fd = mkstemp(temp_name.data())) >= 0) {
            state->temp_name = temp_name.data();
// Preserve ownership and attributes
#ifdef HAS_LIBATTR
            attr_copy_file(state->real_name.c_str(), state->temp_name.c_str(), nullptr, nullptr);
#endif
#ifdef HAS_LIBACL
            perm_copy_file(state->real_name.c_str(), state->temp_name.c_str(), nullptr);
#endif
            fchmod(state->fd, state->file_info.st_mode);
            fchown(state->fd, -1, state->file_info.st_gid);
            fchown(state->fd, state->file_info.st_uid, -1);
          } else {
            state->temp_name.clear();
            if ((state->fd = open(state->real_name.c_str(), O_WRONLY | O_CREAT, CREATE_MODE)) < 0) {
              return rw_result_t(rw_result_t::ERRNO_ERROR, errno);
            }
          }

So all I did was change one line of code:

          if ((state->fd = mkstemp(temp_name.data())) >= 0) {

becomes this

          if (geteuid() == state->file_info.st_uid
              && (state->fd = mkstemp(temp_name.data())) >= 0) {

Quite simply, if the one running tilde is not the owner of the file then that's another cause for skipping the double buffering.

Are you're happy with this fix?  May I push it up?

Here's the full git diff.  But if you're happy with it then please allow me to push it up.  I'm looking to start to build some presence in GitHub.

diff --git a/src/filebuffer.cc b/src/filebuffer.cc
index 6004f7a..ede570b 100644
--- a/src/filebuffer.cc
+++ b/src/filebuffer.cc
@@ -291,7 +291,8 @@ rw_result_t file_buffer_t::save(save_as_process_t *state) {
              directly. The latter has some risk (e.g. file truncation due to full disk,
              or corruption due to computer crashes), but these are so small that it is
              worth permitting this if we can't create the temporary file. */
-          if ((state->fd = mkstemp(temp_name.data())) >= 0) {
+          if (geteuid() == state->file_info.st_uid
+              && (state->fd = mkstemp(temp_name.data())) >= 0) {
             state->temp_name = temp_name.data();
 // Preserve ownership and attributes
 #ifdef HAS_LIBATTR

But



To unsubscribe from this group and all its topics, send an email to tilde-text-editor+unsubscrib...@googlegroups.com.

Gertjan Halkes

unread,
Aug 2, 2018, 5:12:58 AM8/2/18
to Joseph Cavallo, Tilde text editor
Hi Joe,

I think that is an excellent short term solution. Long term I still
want to change how Tilde writes files, but I think this will at least
solve the current issue. So please go ahead and send me a pull request
for this, and if I have time this weekend I'll do a new release.

Cheers,
Gertjan

On Tue, 31 Jul 2018 17:03:19 -0400
> >>>>>>>>> m/d/topic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe. To
> >>>>>>>>> unsubscribe from this group and all its topics, send an
> >>>>>>>>> email to tilde-text-edi...@googlegroups.com. To
> >>>>>>>>> post to this group, send email to
> >>>>>>>>> tilde-text-editor@googlegro ups.com. To view this
> >>>>>>>>> discussion on the web visit https://groups.google.co
> >>>>>>>>> m/d/msgid/tilde-text-editor/26d2cb4c-06a6-49c0-9f43-dcaa7060
> >>>>>>>>> 169f%40googlegroups.com
> >>>>>>>>> <https://groups.google.com/d/msgid/tilde-text-editor/26d2cb4c-06a6-49c0-9f43-dcaa7060169f%40googlegroups.com?utm_medium=email&utm_source=footer> .
> >>>>>>>>> For more options, visit https://groups.google.com/d/optout.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> --
> >>>>>>>> You received this message because you are subscribed to a
> >>>>>>>> topic in the Google Groups "Tilde text editor" group.
> >>>>>>>> To unsubscribe from this topic, visit
> >>>>>>>> https://groups.google.com/d/topic/tilde-text-editor/fCcEU2Hl
> >>>>>>>> o_E/unsubscribe.
> >>>>>>>> To unsubscribe from this group and all its topics, send an
> >>>>>>>> email to tilde-text-edi...@googlegroups.com.
> >>>>>>>> To post to this group, send email to
> >>>>>>>> tilde-text-editor@googlegroups .com.
> >>>>>>>> To view this discussion on the web visit
> >>>>>>>> https://groups.google.com/d/msgid/tilde-text-editor/a0bdea56
> >>>>>>>> -08f4-45fc-813f-b53d11326d9b%40googlegroups.com
> >>>>>>>> <https://groups.google.com/d/msgid/tilde-text-editor/a0bdea56-08f4-45fc-813f-b53d11326d9b%40googlegroups.com?utm_medium=email&utm_source=footer>
> >>>>>>>> .
> >>>>>>>>
> >>>>>>>> For more options, visit https://groups.google.com/d/optout.
> >>>>>>>>
> >>>>>>>
> >>>>>>> --
> >>>>>> You received this message because you are subscribed to a
> >>>>>> topic in the Google Groups "Tilde text editor" group.
> >>>>>> To unsubscribe from this topic, visit
> >>>>>> https://groups.google.com/d/to
> >>>>>> pic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe. To unsubscribe
> >>>>>> from this group and all its topics, send an email to
> >>>>>> tilde-text-edi...@googlegroups.com. To post to
> >>>>>> this group, send email to tilde-text-editor@googlegroups .com.
> >>>>>> To view this discussion on the web visit
> >>>>>> https://groups.google.com/d/msgid/tilde-text-editor/42adf1b3
> >>>>>> -194a-4694-95bc-e90d42e70631%40googlegroups.com
> >>>>>> <https://groups.google.com/d/msgid/tilde-text-editor/42adf1b3-194a-4694-95bc-e90d42e70631%40googlegroups.com?utm_medium=email&utm_source=footer>
> >>>>>> .
> >>>>>>
> >>>>>> For more options, visit https://groups.google.com/d/optout.
> >>>>>>
> >>>>>
> >>>>> --
> >>>> You received this message because you are subscribed to a topic
> >>>> in the Google Groups "Tilde text editor" group.
> >>>> To unsubscribe from this topic, visit
> >>>> https://groups.google.com/d/to
> >>>> pic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe. To unsubscribe
> >>>> from this group and all its topics, send an email to
> >>>> tilde-text-edi...@googlegroups.com. To post to this
> >>>> group, send email to tilde-te...@googlegroups.com .
> >>>> To view this discussion on the web visit
> >>>> https://groups.google.com/d/ms
> >>>> gid/tilde-text-editor/8b6c1d63-6619-452a-b4aa-f623a6cf7566%
> >>>> 40googlegroups.com
> >>>> <https://groups.google.com/d/msgid/tilde-text-editor/8b6c1d63-6619-452a-b4aa-f623a6cf7566%40googlegroups.com?utm_medium=email&utm_source=footer> .
> >>>>
> >>>> For more options, visit https://groups.google.com/d/optout.
> >>>>
> >>>
> >>>
> >> --
> > You received this message because you are subscribed to a topic in
> > the Google Groups "Tilde text editor" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/
> > topic/tilde-text-editor/fCcEU2Hlo_E/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to
> > tilde-text-edi...@googlegroups.com.
> > To post to this group, send email to
> > tilde-te...@googlegroups.com. To view this discussion on the
> > web visit https://groups.google.com/d/
> > msgid/tilde-text-editor/8eb8019e-3d40-434b-86f9-
> > 0b33c47b798c%40googlegroups.com
> > <https://groups.google.com/d/msgid/tilde-text-editor/8eb8019e-3d40-434b-86f9-0b33c47b798c%40googlegroups.com?utm_medium=email&utm_source=footer> .
Reply all
Reply to author
Forward
0 new messages