Re: [Lazarus] Safe temp file name
Thanks Graeme,Its like what I do so it seems Im doing OK. I looked at the code and it seems it just remove { and }. > if (LValue[1] = '{') and (LValue[cGUIDLength] = '}') then LValue > := Copy(lValue, 2, cGUIDLength - 2); AAssignTo.AsString := LValue; It seems it doesnt remove "-" . > This may be an appropriate use for EnterCriticalSection and > ExitCriticalSection, although why don't you just use a different > "prefix" in the call to GetTempFile for each thread. Yes I can but GUID is easier to use. > I wasn't aware that GetTempFileName isn't threadsafe. (Are you sure your code is correct?) Yea. If you look at the implementation it just check until there isnt a file so if 2 thread get a filename before they create it it cause a problem. In my case I made 100 thread and they will create temp file and use them,simple but some time it will happen. > var GUID : TGUID; begin if CreateGUID(GUID) = 0 then begin MyFileName := GuiDToString(Guid); end; Thanks. Regards, Ara -- http://www.fastmail.com - mmm... Fastmail... -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Safe temp file name
On 2015-11-25 15:27, Aradeonas wrote: >> > if (LValue[1] = '{') and(LValue[cGUIDLength] = '}') thenLValue >> > := Copy(lValue, 2, cGUIDLength - 2); AAssignTo.AsString := LValue; > It seems it doesnt remove "-" . > Oops, my mistake. Yes, only { and } is removed in tiOPF code. Regards, - Graeme - -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Safe temp file name
On Wed, Nov 25, 2015 at 05:51:41AM -0800, Aradeonas wrote: > Hi, > > I used GetTempFileName in a multi thread system and it causes problems > as you guess already. So the best way in my mind is using GUID and maybe > use it in a loop for checking not existing for extra safety. But I want > to know is there any clean implementation already that I dont know of? It's pointless to check whether the file exists, since there's a race between checking whether the file exists and creating/using it. You need something that creates the file atomically only if it doesn't exist. For posix use open(2) with O_CREAT | O_EXCL. For Windows use CreateFile() with CREATE_NEW. When this fails, try again with another file name. Henry -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Safe temp file name
Graeme Geldenhuys wrote: Oops, my mistake. Yes, only { and } is removed in tiOPF code. Why are the { and } actually removed? As far as I know they can be part of a filename on all OSes (or am I wrong?) Grtz, Rik (rvk) -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Safe temp file name
On 2015-11-25 15:41, Rik van Kekem wrote: > Why are the { and } actually removed? > > As far as I know they can be part of a filename on all OSes (or am I wrong?) In tiOPF (the code I linked too), GUID's are used as an OID (Object ID), and normally stored in a database field of type char(36). The { and } was simply removed to save 2 bytes per record. I guess the "-" symbol was left in place to make reading the OIDs (by a human) a bit easier - most likely for debugging purposes only. As for using the GUID value as a file name... I always followed the example of tiOPF, but yes, modern file systems will allow the { and } symbols in the file name without problem. Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] FPC Pestering Peacock (3.0.0) release
On 11/25/2015 05:36 PM, Anthony Walter wrote: Sweeet! For Linux users here is a complete FPC 3.0 release + Lazarus from svn build script: http://cache.getlazarus.org/download/linux/install-3.0.sh without looking... 1. does this install to the system default or does it install to a user's home directory? 2. are there any prerequisites (like an existing system or user installation) necessary? 3. will this work with an existing fpcup installation? (my existing fpcup installation is broken and i've not had time to figure it all out again which generally results in blowing it all away and pulling it fresh all over again) -- NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list* unless private contact is specifically requested and granted. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] FPC Pestering Peacock (3.0.0) release
wkitty, I just updated the installers at: http://www.getlazarus.org/setup/ It is built from FPC 3.0 now. It installs to your home folder without needing any special rights to install. Linux/Mac users can change the install folder by changing the $BASE variable at the top of the script. Windows users can just pick a folder in the installer program. Lazarus and FPC configurations are read from their own directories and wont interfere with other existing installations. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] FPC Pestering Peacock (3.0.0) release
Sweeet! For Linux users here is a complete FPC 3.0 release + Lazarus from svn build script: http://cache.getlazarus.org/download/linux/install-3.0.sh -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] FPC Pestering Peacock (3.0.0) release
Joost, can you please remove the "experimental" tag next to the generic bullet? I haven't seen any issues with them in quite a while. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] FPC Pestering Peacock (3.0.0) release
Same here, nobody home at that address. Gordon. On 11/26/2015 05:29 PM, Bee wrote: > The 3.0.0 docs is available at > http://www.freepascal.org/docs-html/3.0.0/fpctoc.htm The doc can't be open. 404. -- -Bee- -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] FPC Pestering Peacock (3.0.0) release
Thank you. G. On 11/26/2015 08:31 PM, Michael Van Canneyt wrote: On Thu, 26 Nov 2015, Vincent Snijders wrote: 2015-11-26 5:29 GMT+01:00 Bee: The 3.0.0 docs is available at http://www.freepascal.org/docs-html/3.0.0/fpctoc.htm The doc can't be open. 404. http://www.freepascal.org/docs-html/3.0.0/fpctoc.html I created a symlink so it will open. Michael. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Safe temp file name
Thank you Graeme. Can you point me to where this system implemented in tiOPF? Regards, Ara -- http://www.fastmail.com - The professional email service -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Safe temp file name
This may be an appropriate use for EnterCriticalSection and ExitCriticalSection, although why don't you just use a different "prefix" in the call to GetTempFile for each thread. On 25/11/15 13:51, Aradeonas wrote: Hi, I used GetTempFileName in a multi thread system and it causes problems as you guess already. So the best way in my mind is using GUID and maybe use it in a loop for checking not existing for extra safety. But I want to know is there any clean implementation already that I dont know of? Regards, Ara -- http://www.fastmail.com - The way an email service should be -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Safe temp file name
Aradeonas wrote: > I used GetTempFileName in a multi thread system and it causes problems > as you guess already. I wasn't aware that GetTempFileName isn't threadsafe. (Are you sure your code is correct?) Graeme Geldenhuys wrote: On 2015-11-25 13:51, Aradeonas wrote: So the best way in my mind is using GUID and maybe use it in a loop for checking not existing for extra safety. So I think it is a pretty safe option to use as a temp file name, even in a multi-threaded environment. Even Microsoft advises it in case you use GetTempFileName excessively. > Due to the algorithm used to generate file names, *GetTempFileName* can perform poorly when creating a large number of files with the same prefix. In such cases, it is recommended that you construct unique file names based on *GUID*s. So it should be safe to use GUIDs for tempfilenames. FPC trunk has this: Guid := TGUID.NewGuid.toString; (I'm not sure if FPC 2.6.4 also some helpers for creating GUIDs) Grtz, Rik (rvk) -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Safe temp file name
Rik van Kekem wrote: (I'm not sure if FPC 2.6.4 also some helpers for creating GUIDs) This will work in FPC 2.6.4: var GUID : TGUID; begin if CreateGUID(GUID) = 0 then begin MyFileName := GuiDToString(Guid); end; You could strip the {, } and - if you want. Grtz, Rik (rvk) -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] FPC Pestering Peacock (3.0.0) release
On Thu, 26 Nov 2015, Vincent Snijders wrote: 2015-11-26 5:29 GMT+01:00 Bee: The 3.0.0 docs is available at http://www.freepascal.org/docs-html/3.0.0/fpctoc.htm The doc can't be open. 404. http://www.freepascal.org/docs-html/3.0.0/fpctoc.html I created a symlink so it will open. Michael. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] Safe temp file name
Hi, I used GetTempFileName in a multi thread system and it causes problems as you guess already. So the best way in my mind is using GUID and maybe use it in a loop for checking not existing for extra safety. But I want to know is there any clean implementation already that I dont know of? Regards, Ara -- http://www.fastmail.com - The way an email service should be -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] OmniPascal: Visual Studio Code Pascal Extension
Dies it support Debugging? Am 25.11.15 um 15:10 schrieb Anthony Walter: In the event you haven't noticed, last week someone posted an announcement of a Free Pascal/Lazarus extension to Visual Studio Code: http://www.omnipascal.com/ I installed it but so far I can't get the code insight working correctly. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] Safe temp file name
On 2015-11-25 13:51, Aradeonas wrote: > So the best way in my mind is using GUID and maybe > use it in a loop for checking not existing for extra safety. I've used GUID's as temp file names in a CGI application for about 5 years. The CGI app gets accessed all at the same time in a classroom environment by about 30-80 kids. I've never hit a duplicate GUID issue. I'm not saying it is impossible, I'm just saying the chances are very very slim. In tiOPF I also use GUID's as Object ID's. I've multiple times imported data which generates about 80,000-100,000 objects in memory in an instant. Again, used this software for many years, and never hit a single duplicate GUID. So I think it is a pretty safe option to use as a temp file name, even in a multi-threaded environment. Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] OmniPascal: Visual Studio Code Pascal Extension
In the event you haven't noticed, last week someone posted an announcement of a Free Pascal/Lazarus extension to Visual Studio Code: http://www.omnipascal.com/ I installed it but so far I can't get the code insight working correctly. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] FPC Pestering Peacock (3.0.0) release
> The 3.0.0 docs is available at > http://www.freepascal.org/docs-html/3.0.0/fpctoc.htm The doc can't be open. 404. -- -Bee- -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] FPC Pestering Peacock (3.0.0) release
2015-11-26 5:29 GMT+01:00 Bee: > > > The 3.0.0 docs is available at > > http://www.freepascal.org/docs-html/3.0.0/fpctoc.htm > > The doc can't be open. 404. > http://www.freepascal.org/docs-html/3.0.0/fpctoc.html Vincent -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus