Re: Unreliable File Deletion

2021-03-30 Thread John Balgenorth via use-livecode
I have only read this one entry your subject so I may not be of any help
but LiveCode is written using C++ and here is a link  with some  info
about temporary files;

https://en.cppreference.com/w/cpp/io/c/tmpfile

The above link mentions,

If the program closes the file, e.g. by executing std::fclose, the file is 
automatically deleted.

It seemed to me you were interested in deleting a temporary file and it is
possible the ability to delete a temporary file is not built in and won’t be
nor is it a bug.  If I remember correctly the proper way would  be to do
a flush on the file instead of deleting it. That deletes everything in the
file and you do not bother deleting it because it is deleted automatically
when your program closes and after it is flushed the memory used will
not be an issue either because it is cleared.

JB

> On Mar 30, 2021, at 3:02 AM, R.H. via use-livecode 
>  wrote:
> 
> Referring Date: 2021-03-29 09:04:04 +0100
> From: Mark Waddingham 
> Subject: Re: Unreliable File Deletion
> Message-ID: 
> 
> Environment: Windows 10, 64bit
> LC: Version 9.6.1
> 
> Dear Mark, Richard and all
> 
> Thank you for your replies ))).
> 
> Your comments are -- of course -- right, but I made a mistake in posting
> something that was incorrectly typed.
> 
> Your wrote:
>> ll cases of people reporting bugs with 'delete file' on Windows that I
>> have seen fall into one of two cases:
>> 1) The path they give to 'delete file' is wrong.
>> 2) The file they are trying to delete is open by the app, or by another
> app.
> 
> I am using URL ("binfile:"&) to read and write from and to the
> file.
> For deleting I was and I am using and always have been using "delete file
> ".
> 
> Unfortunately, I stated this incorrectly when retyping it to compose it as
> part of my message as I changed the original statement here and there, but
> it is not in the actual statement. This is my mistake to post it as such
> and I apologize.
> 
> The file is in a writeable/readable location. It is neither protected, nor
> is it used by any other service/app.
> 
> On my system (Windows 10) asking for specialfolderpath("resources") result
> in the following path: "C:/Users/Roland/Documents/LC-Recent/LSP_App". This
> is so because I put it there.
> 
> It is in the DOCUMENTS folder and therefore should not give problems.
> But the same problem with deleting appears also when using
> specialfolderpath("documents").
> 
> At other times, it worked! It is not something that is very transparent for
> now.
> 
> Since on the Desktop and in any such user directory I can delete files
> without assigning Admin rigths, the problem should not be a system problem.
> I can also issue a shell command, as I posted, to delete and it works well
> without problems. This at least is my fallback in case LC does not delete
> my temporary file/s. So, actually, I use my function and do not care as it
> solves what it needs to solve (just replace the wrong "delete file
> (binfile.." part and put "delete file ").
> 
> I know that other apps can use files and then it will be possible to delete
> such files for good reasons. But that is not the case here.
> 
> I can investigate other possibilities, but nevertheless, it should work in
> such directory. If I find the time to check out the error also looking at
> the system message, I will do and post if there is anything that makes it
> more clear.
> 
> Thanks Richard for posting your additional error investigation. I will
> check it out later as currently I am in a rush job.
> 
> Your posting:
>> delete file tFile
>> if the result is not empty then
>> answer the result &" ("& sysError() &")"
>> end if
> 
> Regards to everyone here
> Roland
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Unreliable File Deletion

2021-03-30 Thread R.H. via use-livecode
Referring Date: 2021-03-29 09:04:04 +0100
From: Mark Waddingham 
Subject: Re: Unreliable File Deletion
Message-ID: 

Environment: Windows 10, 64bit
LC: Version 9.6.1

Dear Mark, Richard and all

Thank you for your replies ))).

Your comments are -- of course -- right, but I made a mistake in posting
something that was incorrectly typed.

Your wrote:
> ll cases of people reporting bugs with 'delete file' on Windows that I
> have seen fall into one of two cases:
> 1) The path they give to 'delete file' is wrong.
> 2) The file they are trying to delete is open by the app, or by another
app.

I am using URL ("binfile:"&) to read and write from and to the
file.
For deleting I was and I am using and always have been using "delete file
".

Unfortunately, I stated this incorrectly when retyping it to compose it as
part of my message as I changed the original statement here and there, but
it is not in the actual statement. This is my mistake to post it as such
and I apologize.

The file is in a writeable/readable location. It is neither protected, nor
is it used by any other service/app.

On my system (Windows 10) asking for specialfolderpath("resources") result
in the following path: "C:/Users/Roland/Documents/LC-Recent/LSP_App". This
is so because I put it there.

It is in the DOCUMENTS folder and therefore should not give problems.
But the same problem with deleting appears also when using
specialfolderpath("documents").

At other times, it worked! It is not something that is very transparent for
now.

Since on the Desktop and in any such user directory I can delete files
without assigning Admin rigths, the problem should not be a system problem.
I can also issue a shell command, as I posted, to delete and it works well
without problems. This at least is my fallback in case LC does not delete
my temporary file/s. So, actually, I use my function and do not care as it
solves what it needs to solve (just replace the wrong "delete file
(binfile.." part and put "delete file ").

I know that other apps can use files and then it will be possible to delete
such files for good reasons. But that is not the case here.

I can investigate other possibilities, but nevertheless, it should work in
such directory. If I find the time to check out the error also looking at
the system message, I will do and post if there is anything that makes it
more clear.

Thanks Richard for posting your additional error investigation. I will
check it out later as currently I am in a rush job.

Your posting:
> delete file tFile
>  if the result is not empty then
>  answer the result &" ("& sysError() &")"
>  end if

Regards to everyone here
Roland
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Unreliable File Deletion

2021-03-29 Thread Mark Waddingham via use-livecode

On 2021-03-28 18:11, R.H. via use-livecode wrote:

@ Peter Reid

Your message found my attention.
Also I am working on Windows 10 and have the same problem using LC 
9.6.1

Indy version.

The similar or same problem as you have: I want to delete the text 
file.

The command I issue is "detele file ". The error it returns:
"Can't delete file".


All cases of people reporting bugs with 'delete file' on Windows that I 
have seen fall into one of two cases:


1) The path they give to 'delete file' is wrong.

2) The file they are trying to delete is open by the app, or by another 
app.


In terms of (1) - its easy to determine - log the path you are using, or 
use 'there is a file ' (but make sure the file you are 
checking for / logging *is* actually the same path as being passed to 
'delete file').


In terms of (2) - Windows and UNIX-derived OSes have a critical 
difference when it comes to filesystems - in UNIX land you can delete a 
file which another process has open, on Windows you can't. (Note: It is 
possible for multiple processes on Windows to open the same file, if 
none have requested exclusive access, but the file cannot be 
deleted/renamed/moved until it is not open by any process).



... // Delete temp file

... delete file ("binfile:")
... put the result into tResult
... if "can't delete that file" is in tResult then

.. myMSG tHInfo & "File could not be deleted." & tFilePath --> 
My

message handler


This script falls into category (1) above - you are giving delete file a 
binfile URL. The 'delete file' command requires a normal file path, not 
a URL of any kind.


Warmest Regards,

Mark.

--
Mark Waddingham ~ m...@livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Unreliable File Deletion

2021-03-28 Thread Tore Nilsen via use-livecode


> 28. mar. 2021 kl. 22:55 skrev J. Landman Gay via use-livecode 
> :
> 
> Interesting. Does it also work on a different machine where you aren't the 
> owner? If so, everything we've heard is wrong.

I haven’t tried on a machine where I am not the owner. This may be why it 
worked. When I come to think of it I am not certain I have been writing to the 
resource folder in any of the apps I have given my students, but I am quite 
certain I have read from such files.

Tore
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Unreliable File Deletion

2021-03-28 Thread Tore Nilsen via use-livecode


> 28. mar. 2021 kl. 21:20 skrev J. Landman Gay via use-livecode 
> :
> 
> 
> Desktop and documents folders are okay, and it may be possible to read from 
> the resources folder, but do you actually write to it? I don't know any OS 
> that allows altering an executable, which includes Mac bundles.

I set up an application with the following code in the  stack script:

on preOpenStack
   put specialFolderPath("resources")& "/testfolder/" into tURL
   create folder tURL
end preOpenStack

In the script of a button I put the following:

on mouseUp

ask "Write something to go into the resource folder:"

put it into tText

put "file:" & specialFolderPath("resources") & "/testfolder/test.txt" into tURL

put url tURL into tData

put tText & return after tData

put textEncode(tData,"UTF-8") into url tURLanswer url tURL

end mouseUp


I then build a standalone for Mac and started the application. After running 
the script from the button three times I did find the file test.txt in the 
folder named «testfolder» inside the _MacOS folder in the contents folder of 
the app bundle. The file contained the exact three lines I had written. Whether 
or not this will work on windows I don’t know as I do not have any computer 
running Windows to try it on.

Best regards
Tore
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Unreliable File Deletion

2021-03-28 Thread J. Landman Gay via use-livecode

On 3/28/21 1:55 PM, Tore Nilsen via use-livecode wrote:

I just made a test application where I am able to create a folder in the 
resources folder on preOpenStack. I then am able to read from and write to a 
document in this folder without any problem. This is on macOS Big Sur. The path 
to my folder in the resources folder in the app bundle is 
«Contents/_MacOS/testfolder/« and the application can write to this folder 
without any questions about permissions.


Interesting. Does it also work on a different machine where you aren't the owner? If so, 
everything we've heard is wrong.


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Unreliable File Deletion

2021-03-28 Thread Richard Gaskin via use-livecode

R.H. wrote:

> The similar or same problem as you have: I want to delete the text
> file. The command I issue is "detele file ". The error it
> returns: "Can't delete file".

LC's result will tell you only the general fact that a file I/O 
operation failed, but not why.


The syserror() function will tell you why, delivering the specific 
integer code for the error the OS reported back to LC.


Establishing a habit of always including a call to sysError when 
reporting a non-empty result will save you countless hours of diagnostic 
time, e.g.:


  delete file tFile
  if the result is not empty then
  answer the result &" ("& sysError() &")"
  end if


--
 Richard Gaskin
 Fourth World Systems
 Software Design and Development for the Desktop, Mobile, and the Web
 
 ambassa...@fourthworld.comhttp://www.FourthWorld.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Unreliable File Deletion

2021-03-28 Thread J. Landman Gay via use-livecode

On 3/28/21 12:28 PM, ELS Prothero via use-livecode wrote:

Folks,
This alarms me.
In my app, I write a file to specialFolderpath(“desktop”).
What are the conditions to make this work on Apple or Windows standalones?


Desktop works fine, every user has permissions to alter files there.

--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Unreliable File Deletion

2021-03-28 Thread J. Landman Gay via use-livecode

On 3/28/21 1:40 PM, Tore Nilsen via use-livecode wrote:

In MacOS the resources folder is part of the application bundle and resides 
within the content folder in that bundle. I have never encountered any problem 
with this folder even when using un-notarized and unsigned apps. I give away 
small apps to my students (both Mac and Windows) all the time and I use 
resources, desktop and documents as the main folders to write to and read from. 
All of these folders work OK.


Desktop and documents folders are okay, and it may be possible to read from the resources 
folder, but do you actually write to it? I don't know any OS that allows altering an 
executable, which includes Mac bundles.


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software   | http://www.hyperactivesw.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Unreliable File Deletion

2021-03-28 Thread Tore Nilsen via use-livecode


> 28. mar. 2021 kl. 20:40 skrev Tore Nilsen via use-livecode 
> :
> 
> 
> 
>> 28. mar. 2021 kl. 19:22 skrev Klaus major-k via use-livecode 
>> :
>> 
>> Hi friends,
>> 
>>> Am 28.03.2021 um 19:11 schrieb R.H. via use-livecode 
>>> :
>>> ...
>>> ... put specialfolderpath("resources") &"/temp.txt" into tFilePath
>>> ... put tOut into URL("binfile:")
>>> ...
>> 
>> you may already know this, but this will not work in a standalone!
>> We will surely not have write permissions in that folder!
>> 
> 
> 
> To the best of my knowledge, I think this is wrong. In MacOS the resources 
> folder is part of the application bundle and resides within the content 
> folder in that bundle. I have never encountered any problem with this folder 
> even when using un-notarized and unsigned apps. I give away small apps to my 
> students (both Mac and Windows) all the time and I use resources, desktop and 
> documents as the main folders to write to and read from. All of these folders 
> work OK. The user will be asked if they want to give the application 
> permission to access these folders, but other than that I don’t know of any 
> hiccups. 
> 
> I know that there are several restrictions when you deploy to various mobile 
> platforms. These are explained in the Dictionary.
> 

I just made a test application where I am able to create a folder in the 
resources folder on preOpenStack. I then am able to read from and write to a 
document in this folder without any problem. This is on macOS Big Sur. The path 
to my folder in the resources folder in the app bundle is 
«Contents/_MacOS/testfolder/« and the application can write to this folder 
without any questions about permissions.

Best regards 
Tore

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Unreliable File Deletion

2021-03-28 Thread Tore Nilsen via use-livecode


> 28. mar. 2021 kl. 19:22 skrev Klaus major-k via use-livecode 
> :
> 
> Hi friends,
> 
>> Am 28.03.2021 um 19:11 schrieb R.H. via use-livecode 
>> :
>> ...
>> ... put specialfolderpath("resources") &"/temp.txt" into tFilePath
>> ... put tOut into URL("binfile:")
>> ...
> 
> you may already know this, but this will not work in a standalone!
> We will surely not have write permissions in that folder!
> 


To the best of my knowledge, I think this is wrong. In MacOS the resources 
folder is part of the application bundle and resides within the content folder 
in that bundle. I have never encountered any problem with this folder even when 
using un-notarized and unsigned apps. I give away small apps to my students 
(both Mac and Windows) all the time and I use resources, desktop and documents 
as the main folders to write to and read from. All of these folders work OK. 
The user will be asked if they want to give the application permission to 
access these folders, but other than that I don’t know of any hiccups. 

I know that there are several restrictions when you deploy to various mobile 
platforms. These are explained in the Dictionary.

Best regards
Tore Nilsen







___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Unreliable File Deletion

2021-03-28 Thread ELS Prothero via use-livecode
Folks,
This alarms me. 
In my app, I write a file to specialFolderpath(“desktop”).
What are the conditions to make this work on Apple or Windows standalones?

Bill

William Prothero
https://earthlearningsolutions.org

> On Mar 28, 2021, at 10:22 AM, Klaus major-k via use-livecode 
>  wrote:
> 
> Hi friends,
> 
>> Am 28.03.2021 um 19:11 schrieb R.H. via use-livecode 
>> :
>> ...
>> ... put specialfolderpath("resources") &"/temp.txt" into tFilePath
>> ... put tOut into URL("binfile:")
>> ...
> 
> you may already know this, but this will not work in a standalone!
> We will surely not have write permissions in that folder!
> 
> As a workaround I would probably use -> specialfolderpath("temporary")
> Or even write the text to -> the tempname
> 
> Both are available on all platform and you do not have to think about 
> deleting that file later, the OS will take care of this. :-)
> 
> 
> Best
> 
> Klaus
> --
> Klaus Major
> https://www.major-k.de
> https://www.major-k.de/bass
> kl...@major-k.de
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Unreliable File Deletion

2021-03-28 Thread Klaus major-k via use-livecode
Hi friends,

> Am 28.03.2021 um 19:11 schrieb R.H. via use-livecode 
> :
> ...
> ... put specialfolderpath("resources") &"/temp.txt" into tFilePath
> ... put tOut into URL("binfile:")
> ...

you may already know this, but this will not work in a standalone!
We will surely not have write permissions in that folder!

As a workaround I would probably use -> specialfolderpath("temporary")
Or even write the text to -> the tempname

Both are available on all platform and you do not have to think about 
deleting that file later, the OS will take care of this. :-)


Best

Klaus
--
Klaus Major
https://www.major-k.de
https://www.major-k.de/bass
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Unreliable File Deletion

2021-03-28 Thread R.H. via use-livecode
@ Peter Reid

Your message found my attention.
Also I am working on Windows 10 and have the same problem using LC 9.6.1
Indy version.

The problem with copying text to the clipboard and then pasting it into
other applications results in inserting double lines. I think there was a
discussion about the clipboard on the forum or here recently. Instead of
directly copying the text, I create a temp file temp.txt, insert the text
to be copied, then read the file and then I can paste the text reliably.
The file is then deleted.

The similar or same problem as you have: I want to delete the text file.
The command I issue is "detele file ". The error it returns:
"Can't delete file".

So, I tried using a forced Shell command which did not work (probably it
needs Admin rights). But the standard Shell command deletes the file.

Here is the script snippet:

// The original purpose of using this script as part of a larger script is
to copy column names of a database table to the clipboard and insert them
anywhere.

## Script snippet calling Shell (Windows 10/64)
// Save data to external file to get rid of wrong carriage returns in
Windows
// Copy data as text to the clipboard
// Space are replaced by "." for this message list
// A temporary text file is created and shall be deleted after usage
// tOut contains the resulting data from before...
//  myMsg is a separate custom message handler that directs messages either
to the message box, writes to a log file or places the message into a
field, or all together...)

... local tOut
... local tFilePath
... local tResult
... local tCmd

... put specialfolderpath("resources") &"/temp.txt" into tFilePath
... put tOut into URL("binfile:")
... put URL("binfile:") into tOut
... set the clipboarddata["text"] to tOut

... // Delete temp file
... delete file ("binfile:")
... put the result into tResult
... if "can't delete that file" is in tResult then

.. myMSG tHInfo & "File could not be deleted." & tFilePath --> My
message handler
.. if the platform is "win32" then
. set the hideConsoleWindows to true
. replace "/" with "\" in tFilePath
. put quote & tFilePath & quote into tFilePath
. put "del " into tCmd -- this shell command works for me
. put shell(tCmd) into tResult
. put CR& the result after tResult
. /* Comment: Error messages appear when using "rmdir /s /q"
. to force delete the file
. Error message: Invalid switch - "Users".  */
. myMSG tHInfo & tResult --> My message handler
.. end if
... end if
##/ End script snipped

So, if other users have the problem that a file cannot be deleted with the
"delete file" command (even though it he file tit is not flagged as part of
another process or flagged as "cant delete") then this seems to be a bug.

I would report it if I am not the only one seeing the problem.

Roland
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode