Link to home
Start Free TrialLog in
Avatar of Michael McComb
Michael McComb

asked on

source of duplicated file name on save warning

im using debian, ubuntu, linux, mint, ext4 if that specific info helps

when saving a file from within notepad ap or from within the libreoffice word processor ap the exact same message box appears when saving to a file name that already exists.....  it warns that the file already exists and asks if one wishes to cancel or overwrite.....   does this identical message box originate from the application or the OS?   and is the fact that the file already exists determined within the ap or is the message box generated by info passed between the ap and the OS

rename fails when renaming to a filename that already exists but mv and cp overwrite with no warnings.....
Screenshot-from-2019-02-25-13-41-48.png
Avatar of Owen Rubin
Owen Rubin
Flag of United States of America image

The OS toolbox for opening, closing and saving files I believe handles that error. I suspect it is the GUI interface on top of Linux that generates the dialog from the error returned on the file action by the system.

That said, the application initiates the save, and receives the error when trying to save a file. Usually the dialog is part of the OS's GUI toolbox for saving files, and puts up the dialog for you. I do not know if your OS/GUI allows the app to override the system's dialog and put up their own. I do not see why an app would do this unless they want to take some action on duplicate files. Most "standard file" GUI toolboxes allow for dialog box customization as well, which is why open and save sometimes look different.

I assume that error you posted was from within the app? You could drag the file manually to where one already exists and see if the dialog box is different. I suspect they will be the same.
Above edited for completion
Avatar of Michael McComb
Michael McComb

ASKER

thank you for the reply.....yes, the error posted was from in two different apps and absolutely identical therefor i assume it is an os generated response and query as to whether or not the user wished to continue what would be an overwrite....

from what you write i am wishing to modify the behavior of the "OS toolbox" slightly...

again this is an ubuntu linux system i am wishing to modify what you refer to as the "OS toolbox" so as to provide a slightly different functionality between the time that the "OS toolbox" determines that there is indeed an already existing file and the time where it responds with the the prompt box to allow an overwrite of the file or cancel the operation.....

i sort of assume that "OS toolbox" is a generic terminology for a specific part/function of the OS which in turn means that somewhere there is code that handles this..... would you know more specifically where that code would be located or have any ideas as to how i could track the location down?

again, thank you for the help
Avatar of David Favor
If both messages are similar, likely some GUI library like glib2 is being used, so every application calling this GUI library will produce a similar message.

This may also relate to the window manager you're using, so might be a Gnome or KDE applications calling the normal Gnome + KDE GUI services, which will cause all applications to look similar.
time for confession..... i want to rename the file currently "in the way" and then save under the name that the ap is requesting.... so between the os getting the flag of file existence (or whatever we call it) and generating the overwrite/cancel action dialog i want to rename and cancel go around the dialog box call to simply save the file
Yes, sorry, OS Toolbox was what we called it on Apple products. It was also called Standard File. There were plenty of hooks to customize a save dialog.  I have never done this in Linux, but assume it has some if not all of the same functionality.

This page might help: https://developer.gnome.org/gtk3/stable/GtkFileChooserDialog.html
i want to rename the file currently "in the way" and then save under the name that the ap is requesting...

So the only way I could see doing this is to  write some code to create your own save file dialog, then code checking for the file yourself. Then your code would have t rename the existing file, and then proceed with the save as requested.

But this behavior would make me very nervous, as there are too many places to fail. And, it also renames the old file without really asking the user if that is OK.

I would think it would be better to emulate the way MacOS does this now, and to ask if the user wants to Replace, Keep Both, or Cancel. On Keep Both, the current file has a number added to the file name to indicate what version it is. That means the OS has to check for any and all versions on the Keep Both option and then put the right number at the end of the file name.
not really familiar with MacOS but that would be just fine....  if you save three times in a row and answer "Both" each time do you end up with multiple files?    this is the behavior i would like but i don't need it to ask each time but rather just save near duplicates.....  the ap itself will not attempt to save the file if there is no change to the file so that absolute sequentially generated duplicates could not happen....  if you alternated between to versions of the file with the very simplest of changes then multiple copies of very nearly identical files would be created.....

id like to experiment with this but need to find the code that needs "adjustment" :-)
ive got to head out for now..... thank you very much for the hints.... just knowing its in something called the "standard file" will start zeroing me in on the right code..... hope there is a linux guy around too....... i shall return
Ok, "Standard File" was Apple's name for their GUI Toolbox. I do not think others use that name. But to talk about the GUI package that interfaces to Lunix is more correct.  Seeing the command you are using to Save (assuming you are writing a program) would help.

On the Mac, a few apps and the Finder (top level of GUI) offer a dialog that looks like this:

User generated image
If you say Keep Both, the code tries to write the file as is named. If that fails, it tries again by adding "2" (it starts at 2) to the end of the name. Then 3, then 4, etc until it is successful saving the file. The original or older files are not touched (which is the best process actually) and newer files are added.
Note however, that if one of the files gets deleted, the save will backfill that number before making a larger one. In other words, the code does not look for the highest number, but rather simply saves were it can. So if you had a file called Display Adapters.png and already had:

Display Adapters.png
Display Adapters 2.png

The next would be  Display Adapters 3.png, then Display Adapters 4.png, and so on. But if you had this

Display Adapters.png
Display Adapters 2.png
Display Adapters 3.png
Display Adapters 4.png

and deleted Display Adapters 2.png, then the next save would be Display Adapters 2.png and not Display Adapters 5.png because there is a hole. But since you can sort files by date, it is not a real problem.  I happen to like this solution because it is fairly quick, and it also does not touch any older files.

I would do some searching on the Write command that Unbuntu uses to write to a file, as well as the APIs for the the GUI you are using, which I believe is Debian, here is a good place to start: https://wiki.debian.org/DesktopEnvironment
all good stuff so thank you....

i would prefer to do the following and it is what i wish to modify the ubuntu into doing....

when an ap tries to write a file and gets the kick back from the OS (i'm hoping this is how it happens) indicating that the file already exists the OS would simply rename the existing file rather than asking permission to overwrite or abort the write operation....as below....
 
file being edited for instance would be "Display Adapters.png"
if this file already exists and an attempt to save it again occurs the original existing file on disk would be renamed to for instance...
"Display Adapters--190131205432.png" (date string being last mod date) while the file actually being save WOULD still be "Display Adapters.png"

if you did this over and over again you would have something like....
"Display Adapters.png"
"Display Adapters--190225205510.png"
"Display Adapters--190225205438.png"
"Display Adapters--190225205432.png"
"Display Adapters--190131201015.png"

with the "Display Adapters.png" being the last time the file was written OR the most recent version of the file

haven't thought all the way through this yet but i'd probably want to drop the "-- (+12 digits) from the file name if one picked up a dated file and resaved it so that again the most recent file saved would not have a date-time in its name while deleting the read in copy of the file that did have the date/time in the name to avoid ever having a file name like "Display Adapters--190131201015--190201201510.png"

could also do this with simple numbers but it would require re sequencing number part of the file name whenever a numbered file was depleted

filename
filename01
filename02
filename03
filename04

upon the purposeful deletion of "filename02" the system would have to rename "filename03" to "filename02" and "filename04" to "filename03"

i can accomplish either of these scenarios with python3 for specified directories but it seems a clumsy approach to me when what i really want is for this scenario to occur without reference to specific directories....

SO, it seems to me that at the point the decision box is asking one to overwrite the current file OR abort the save.... this would be the ideal place to stick in some code to accomplish the renaming, sequencing and saving of files with the added benefit that it would make no difference what ap caused the box to pop up...

so i suppose another way to ask would be to say precisely WHERE is that box originating......   tmi maybe but it is what i am thinking.....
The only problem I have with your idea is that you would have to rename already existing files. I just think that is dangerous and brings up a possible fail point. I am usually against a program automatically touching existing files unless it is a full replace.

There is one other way to do this. When you save the file, always append the Date and Time out to seconds. Then the files would never collide.  Such as:

"Display Adapters-20190225204312.png"   <--- saved on 02/09/2019 at 20:43:12
"Display Adapters-20190225204325.png"   <--- saved on 02/09/2019 at 20:43:25
"Display Adapters-20190225204403.png"    <--- saved on 02/09/2019 at 20:44:03
etc etc.

If you always use date time to the second you will never have a file collision. This might make this a lot easier.

Just a thought.
just attempted to copy/paste a file from one directory to another directory that already contained the same file and got the following.... SO the copy/paste function has nothing to do with any application but is rather coming from some area of code in the OS.....  HOW would one discover that area of code within the OS so as to be able to attempt a modification such as..... don't ask just overwrite OR don't ask and do nothing
alright...  not an OS function but rather clipboard
keep hopin' some of this spaghetti will stick if i keep hurlin' it at the wall......
I d not know if you can, and trying to override system functions is never recommended, because you app will only work on that specific system. And system upgrades could make your overwrite not work anymore.

I still so go with my previous suggestion, save the file with date and time appended to the end. You will keep all files and never have to rename one, delete one, or do some other strange system patch to get what you want.

I know not the answer you are looking for, but I think it is a much more professional and clean solution.  Your other choice it to see if you can force an over-write on an existing file, replacing it always with the one you are trying to save.

BUT, lets backup. I assumed you were writing a program to do this? Bow I believe what you are asking is IF you can make the Operating System or GUI always rename the old and write the new?  So I need more info. Tell me a few examples of where you would use this?

Sorry, I was thinking you were trying to program an app that would do this.
thanks Owen..... the quick but somewhat dirty answer to this is that I would very much like to have the whole ubuntu/linux/ext4 system present and appear to handle files as if it were a VMS/files-11 system....  on the off chance that you were at anytime a VMS guy this will help but otherwise.....

every time i save a file named "FileA" to a directory i want to save not only "FileA" but also a duplicate of the file named "FileA_(date-time-stamp)" like "FileA_190227100750".  If after doing this one saved the "FileA" again it would update the "FileA" as normal but also create yet another version of the file named for instance "FileA_190227100943" and so on with no limit to the number of copies.  One would always pick up and edit the "FileA" and save to "FileA" while at the same time creating a duplicate but timestamped file.

This was a built in part of the VMS/files-11 system.
The other things you could do with the original system was set a system wide parameter that would indicate how many copies could be made before the oldest ones started falling off.  If you set that system wide parameter to "1" then there would be no apparent difference between it and any other system but if you set it to "3" then with every file saved there could be as many a two previous versions of the file.

You could also set the same type of parameter for any directory which would override the system wide setting for that directory.

There was a purge function where you could say "Purge FileA /keep=4" and all file copies of "FileA" in excess of 4 would be deleted in the order of oldest to newest.

TMI probably but that is the inspiration for getting automatic file versioning.

i'll attach a python script that emulates this just a bit..... there is commentary within the script
also a couple desktop units i click on to either start or stop the python versioning process

while this works it is not how i would name duplicate files if i could have the dups generated by the OS
versioning.py
START-VERSIONING.desktop
STOP-VERSIONING.desktop
the files-11 didn't use a timestamp but rather a sequential number that looked like "FileA.txt;1", "FileA.txt;2","FileA.txt;3", and so on.  I don't even want to try and replicate that but perhaps "FileA_001.txt", "FileA_002.txt", "FileA_003.txt", etc would be fairly ez to get to if i could find the right places to modify current file handling.

probably all a pipe dream but i'd like to get blocked by reality rather than merely give up for not understanding the why of it....
the quick but somewhat dirty answer to this is that I would very much like to have the whole ubuntu/linux/ext4 system present and appear to handle files as if it were a VMS/files-11 system

So funny. When you asked this question originally, the first thing  I thought about was VMS and versions. I used to run several VAX 11/780's and VAX clusters back in the days, so yea, I always loved versioning files. Saved my butt on many occasions.

So I did read this:

No mainstream Linux file system supports versioning, but a number of experimental/research and lesser-known solutions do, namely:
  • ext3cow.
  • NILFS - A log-structured file system supporting versioning of the entire file system and continuous snapshotting.
  • Tux3 - Under active development.
  • btrfs[dubious – discuss]
  • Next3.

So yea, some people are working on this, but I did not look any of them up. I do not think this would be easy, EXCEPT Linux is an open software system. You might poke about in the Ubuntu groups and suggest it as a possible option or upgrade later? Or even look at the file system code and see if it could be done there.

Best I can at this time.

Cheers
beginning to look to me as if i need to pursue GNU core functionality and perhaps alter it.....  pretty deep and way beyond me at the moment but i'm chasing it.....

just finding info that addresses the functionalities is a bit challenging as the vast majority of information starts by assuming the GNU core is in place rather than explaining how it functions....
Sorry I could not of more help, but this sounds like a major task.

There are emulators these days that run VMS. Just not sure what you can run on them!

Good luck
hey owen, souped up the python based Files-11 semi replication a bit and thought you might enjoy a copy of it.....   for one thing the system now keeps files by a file number rather than by a date which makes file names and versioning much more easy to read especially by people accustomed to VMS.....AND in the code you can now specify up to four directories where such file versions will be kept along with how many versions each directory will keep.... range of versions is up to 999 file versions

i use this in a linux OS but i would think that the windows OS would either work with the same code or with only very slight modification

i don't think that the expertise i need in order to attack :-) (modify ext4) functionality is present on the experts-exchange site as you are really the only one who recognized the functionality being sought....   i may need to get to a university and find a linux OS fanatic to find what i need.... just trying to shortcut the dev time as i don't want another degree but rather a very specific change to an existing system

thanks again
versioningBYnumeric.py
i realize that no application is going to interface with a modified ext4 in a fully appropriate way and therefore significant problems would exist with all current applications accessing the system but still i'd like to head down the path... might be able to add a controlling table and the equiv of the python at the OS level and replicate the desired functionality..... just have to find the OS experts to discuss
i realize that no application is going to interface with a modified ext4 in a fully appropriate way and therefore significant problems would exist with all current applications accessing the system but still i'd like to head down the path

a fusefs would be easier to work with. the example fuse that acts like a nullfs should help. hacking a fuse together requires much less rocket science than hacking a filesystem

... but do not expect the task to be simple as there are many ways the initial feature could be implemented and none are easy to work with :

suppose the app checks whether the file exists : are you going to answer files do not exist when they do ?
suppose it tries to open for writing : which flags would trigger saving the file and write elsewhere ?

but fuse would allow to limit that to specific parts of the filesystem so you may be able to work something out for your specific case.

--

as a side note, the GtkFileChooser is quite easy to hack and it might be feasible to submit a patch that allows to set default actions for specific apps that would actually be accepted. likewise if your os is qt or whatever else based. i guess in that case, openoffice is directly compiled against gtk ... ?

been using my python version of the functionality i sought above for quite awhile now and it works perfectly.....  i tweek then save over and over, ten tweeks result in ten versions of the original code.  it i try the last version recorded and something is wrong i just back down through the versions to where it DID still work and start forward from that point...  big time saver if i'm doing multiple parallel changes to the same system....


i do miss my VMS  ;-)


This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.