a way to check whether a file is actually being written on

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

a way to check whether a file is actually being written on

Silent Leaf
Hi,

i created a small clone of dd in haskell. I made it so it only copies block by block and only if there's any difference between each pair of blocks from each file. the idea is to use this dd clone as backup system, especially since my partitions are nearly full, so no real loss in copying the whole things.

I'm wondering if there's any way to check if my program never ever writes onto the target unless actually needed. obviously by reading the code i'd say it does what i want, but we do make test cases rather than rely on what we think the code does.

i can't run it with a target file that would be made read-only in the filesys (and hope for an error for trying to write on it) since obviously i need to open it in read-write right from the beginning, in case of actual need of writing (as apparently i can't have two handles on the same file... although maybe there's a way to change the mode of opening on the run? did not find it in System.IO nor in Hoogle or Hayoo)

so if anyone has an idea, in or outside of haskell, that would be great!

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: a way to check whether a file is actually being written on

Silent Leaf
by the way: dd has this option that says "in case of read error, do not stop, continue". it's recomended to use it altho i never actually gotten why.
my point is: how to handle any kind of read/write exception with my clone? i used withBinaryFile which promised to close my handles no matter what, which is great, but i don't feel much secured since i don't know how my program would handle a bumpy ride or even if it would tell me anything... i don't even know what would happen if it were cut in the middle, etc.

on this general topic, by the way, are there good resources for system-programming with haskell? is it even manageable to do so rather than use c-like (go, c++, etc) languages?

2017-06-27 21:42 GMT+02:00 Silent Leaf <[hidden email]>:
Hi,

i created a small clone of dd in haskell. I made it so it only copies block by block and only if there's any difference between each pair of blocks from each file. the idea is to use this dd clone as backup system, especially since my partitions are nearly full, so no real loss in copying the whole things.

I'm wondering if there's any way to check if my program never ever writes onto the target unless actually needed. obviously by reading the code i'd say it does what i want, but we do make test cases rather than rely on what we think the code does.

i can't run it with a target file that would be made read-only in the filesys (and hope for an error for trying to write on it) since obviously i need to open it in read-write right from the beginning, in case of actual need of writing (as apparently i can't have two handles on the same file... although maybe there's a way to change the mode of opening on the run? did not find it in System.IO nor in Hoogle or Hayoo)

so if anyone has an idea, in or outside of haskell, that would be great!


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: a way to check whether a file is actually being written on

Jona Ekenberg
In reply to this post by Silent Leaf


Den 27 juni 2017 9:47 em skrev "Silent Leaf" <[hidden email]>:
Hi,

i created a small clone of dd in haskell. I made it so it only copies block by block and only if there's any difference between each pair of blocks from each file. the idea is to use this dd clone as backup system, especially since my partitions are nearly full, so no real loss in copying the whole things.

I'm wondering if there's any way to check if my program never ever writes onto the target unless actually needed. obviously by reading the code i'd say it does what i want, but we do make test cases rather than rely on what we think the code does.

i can't run it with a target file that would be made read-only in the filesys (and hope for an error for trying to write on it) since obviously i need to open it in read-write right from the beginning, in case of actual need of writing (as apparently i can't have two handles on the same file... although maybe there's a way to change the mode of opening on the run? did not find it in System.IO nor in Hoogle or Hayoo)

so if anyone has an idea, in or outside of haskell, that would be great!
______________________________
Maybe you can use strace? https://youtu.be/4pEHfGKB-OE
 

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: a way to check whether a file is actually being written on

Silent Leaf
strace sounds really great, i'll test it, thanks :)

2017-06-27 22:42 GMT+02:00 Jona Ekenberg <[hidden email]>:


Den 27 juni 2017 9:47 em skrev "Silent Leaf" <[hidden email]>:
Hi,

i created a small clone of dd in haskell. I made it so it only copies block by block and only if there's any difference between each pair of blocks from each file. the idea is to use this dd clone as backup system, especially since my partitions are nearly full, so no real loss in copying the whole things.

I'm wondering if there's any way to check if my program never ever writes onto the target unless actually needed. obviously by reading the code i'd say it does what i want, but we do make test cases rather than rely on what we think the code does.

i can't run it with a target file that would be made read-only in the filesys (and hope for an error for trying to write on it) since obviously i need to open it in read-write right from the beginning, in case of actual need of writing (as apparently i can't have two handles on the same file... although maybe there's a way to change the mode of opening on the run? did not find it in System.IO nor in Hoogle or Hayoo)

so if anyone has an idea, in or outside of haskell, that would be great!
______________________________
Maybe you can use strace? https://youtu.be/4pEHfGKB-OE
 

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Loading...