Recent

Author Topic: CopyFile  (Read 1483 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
CopyFile
« on: February 08, 2021, 11:20:34 am »
Hello Guys :)

Tried to do CopyFile (wanted to create a Save File as .. ).
now i need to write my own copyfile, bc the existing one is opening the source file with sharedenywrite right in it,
so as long as you have the file open it will not be able to open it.

How do i rewriteCopyFile ?

Thanks :)

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: CopyFile
« Reply #1 on: February 08, 2021, 12:48:59 pm »
What exactly do you want to do?
Is there a need to have the source file open read/write?

If you know that your own program is the only process that has the source file open (with write permission) than simply open the file with "fmOpenRead or fmShareDenyNone".
The actual copying is basic stuff, I take it that you can implement that yourself?

I have a rather elaborate FileCopy routine that provides a callback for e.g. a progressbar.
I use it for my backup program (so I trust the code).
That one uses fmShareDenyWrite also (there is af course a reason for that: if you copy the first block and then some other process rewrites that, your copy may become invalid to the point it cannot be read by the application you designed it for).
You're free to change that.
You can find it at http://svn.code.sf.net/p/flyingsheep/code/trunk/MijnLib/fsifileutils.pp.

Bart

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: CopyFile
« Reply #2 on: February 08, 2021, 01:00:48 pm »
Thanks for ur Reply :)

i just wanted to create an operation wich allows the user to save his progress (a sqlite database)

its a MainMenu with a Tab "Save As.." and if u click it it should create a Copy of the db(wich can later be reopened again).
But i get the Error "Already open", bc my Application uses the File. So i wanted to change the sharedenywrite property or whatever to ShareDenyNone.

Bad Idea ?

LG ?

and i still can't figure out how to override Functions wich are already implemented by a Lazarus Lib. f.eg. "CopyFile"

Thanks

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: CopyFile
« Reply #3 on: February 08, 2021, 01:11:15 pm »
A more simple approach would be to close the database, do the copy, re-open the database.
Especially with a databse I would not recommend copying it if any proces has write access to it.

Bart

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: CopyFile
« Reply #4 on: February 08, 2021, 01:39:44 pm »
Ok that makes it easier. Thanks Bart. :)

What could happen if db is still open and u try to copy the File ?

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: CopyFile
« Reply #5 on: February 08, 2021, 01:42:07 pm »
The DB engine could update the sourcefile (perhaps in OnIdle or similar).
At that point the integrity of the target file is comprimised: it will not be a 1-on-1 copy of the source file.

Bart

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: CopyFile
« Reply #6 on: February 08, 2021, 02:00:34 pm »
Depending on the Data in this SQLite-DB (Is this "progress" just one Table? Do i have to keep track of PrimaryKeys/Foreign Keys? etc.) i'd rather try for a series of SQL-Statements in a second Connection ("CREATE DATABASE", "CREATE TABLE", "INSERT INTO TABLE" blablabla)

EDIT: Or use the Backup-API
https://www.sqlite.org/c3ref/backup_finish.html#sqlite3backupinit
« Last Edit: February 08, 2021, 02:07:24 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Re: CopyFile
« Reply #7 on: February 08, 2021, 03:32:15 pm »
Thanks Guys :)

 

TinyPortal © 2005-2018