Temporary file deleted - ed

I'm working on ed (yes, the editor) source code.
The program uses a scratch file, opened with tmpfile, as a buffer.
But, whenever I run the program, lsof always report the temporary file as deleted! (and in fact it's not there). Why?

Because a file can exist on disk without having a filename associated with it, many programs will open a file and then promptly unlink it. The file contents can continue to be modified & read by open file-handles on the file, and won't actually be removed from the disk until all open file handles are closed.
(this is for *nix/POSIX platforms AFAICT; Windows handles files differently, preventing unlinking if an program has the file-handle still open, and thus reboots are often needed for upgrades to force those open file-handles to be closed so file contents can be replaced)

Related

need to recover trados project with translation

I was working on a language translation project in trados on a virtual machine. Half of the work was done and the translated words were exported into a Word docx file. Upon restarting the virtul machine, the project file appears to have been corrupted as trados shows no signs that the project was worked on. When I manually open the sdlproj (trados project) file, trados cannot open the file mentioning the following:
: An error occured whilst trying to determine the file version
I have tried creating a new project and used pre-translate using batch tasks but that did not seem to have imported the previously translated document. I need to figure out how to recover my project so that I can recover the translated document (so I do not have to redo the work) as well as recover the translation memory for trados. The translation memory folder is present inside the original project folder. I would really appreciate any suggestion to further troubleshoot and fix this issue. I have tried their support desk but they do not appear to be available today. Two solutions I observed from their forum suggested:
save the project file with a zip extension, extract the contents and then open the sdlxiff file from there
recreate the project and use pre-translate.
In my case, I was able to open the sdlxiff file from the translated language directory. This opened the project with the text that had previously been translated. I am not certain whether I need to remove the sdlproj file or simply save the project hoping that it will overwrite the corrupted file. In either case, I will update this post once I get an answer to that.

Why my iOS App's Documents directory became a file?

We are developing an iOS app with Enterprise distribution.
It ran well in hundreds of devices, but we found some iOS 6.1.3 devices failed to launch it hours later the first run, because the App's Documents directory became a file !
Our App did nothing special except it was downloading about 80MB MP4 files from a remote HTTP server.
I assumed that something wrong when it operated the Documents directory, but so far have little clue to identify what's 'dangerous' usage in our codes.
Did you have encountered similar problems? How did you fix it?
Thanks a lot to anybody kindly helping to figure it out.
What I suggest doing is for your app to test for this when it launches, and if there is a file there, move it to some other place (like the temp folder), then create the Documents directory, then move the file back into that directory with the same name (or change the name). That will at least prevent your app from stalling.
If you have any means of remote logging, you could bin hex the first 64 bytes of the file and send it to your service for analysis (if you know what's in the file it should help you figure out who created it.)

File Operations - Copy and Move - Delphi

I need to do a two fold operation in Delphi.
First is reading a directory and copy all of the files into a backup folder. If any of the files are currently in use as being written to and/or open, then bypass that file.
Second is to move the file to another directory. Again, if any of the files are currently in use as being written to and/or open, then bypass that file.
I have used file copy and move before, but I am unsure as to how to detect whether a file is being written to and/or open.
Thanks.
If you use Windows.pas' CopyFile(PChar(sFrom),PChar(sTo),false) it will return false when the copy fails, and GetLastError will return an error-code explaining why.

CodeModuleManager cannot allocate space for the module

I am trying to write an app that will download and install cod files.
I have the line:
CodeModuleManager.createNewModule(codData.length, codData, codData.length);
which is expected to return a module handle (which is an int). However, it returns 0 that means space cannot be allocated for the module to be intalled. I searched a bit but coulndt really find any info about what may be causing this. Any ideas ?
I found the solution:
I used the COD files inside the deliverables/web directory
When the COD file is above some size it is partitioned into 2 (or more) cod files. In my case there were two COD files. One was named abc.cod and the other one was abc-1.cod. You need to have both cod files in order to make the installation. (which was the real problem)
I noticed that in the deliverables/standard folder there is only 1 cod file which is probably the case that it is not splitted into 2 parts and, thus, the CodeModuleManager is not able to allocate space for it as a whole (thus partitioning is necessary afterall)
However, even after this you can encounter problems such as the icon of your application getting disappeared when you overwrite cod files (ie. when you try to update your app which already exists).
I found it more convenient to work with the .jad file. Just set up the right mime types in your directory and put the jad and cod files in there. Then open your jadfile using the browser and your app should be automatically and smoothly installed/updated by the OS itself.
Hope this proves helpful for someone else

keep rsync from removing unfinished source files

I have two machines, speed and mass. speed has a fast Internet connection and is running a crawler which downloads a lot of files to disk. mass has a lot of disk space. I want to move the files from speed to mass after they're done downloading. Ideally, I'd just run:
$ rsync --remove-source-files speed:/var/crawldir .
but I worry that rsync will unlink a source file that hasn't finished downloading yet. (I looked at the source code and I didn't see anything protecting against this.) Any suggestions?
It seems to me the problem is transferring a file before it's complete, not that you're deleting it.
If this is Linux, it's possible for a file to be open by process A and process B can unlink the file. There's no error, but of course A is wasting its time. Therefore, the fact that rsync deletes the source file is not a problem.
The problem is rsync deletes the source file only after it's copied, and if it's still being written to disk you'll have a partial file.
How about this: Mount mass as a remote file system (NFS would work) in speed. Then just web-crawl the files directly.
How much control do you have over the download process? If you roll your own, you can have the file being downloaded go to a temp directory or have a temporary name until it's finished downloading, and then mv it to the correct name when it's done. If you're using third party software, then you don't have as much control, but you still might be able to do the temp directory thing.
Rsync can exclude files matching certain patters. Even if you can't modify it to make it download files to a temporary directory, maybe it has a convention of naming the files differently during download (for example: foo.downloading while downloading for a file named foo) and you can use this property to exclude files which are still being downloaded from being copied.
If you have control over the crawling process, or it has predictable output, the above solutions (storing in a tempfile until finished, then mv'ing to the completed-downloads place, or ignoring files with a '.downloading' kind of name) might work. If all of that is beyond your control, you can make sure that the file is not opened by any process by doing 'lsof $filename' and checking if there's a result. Clearly if no one has the file open, it's safe to move it over.

Resources