A File Reference and its evolving life!

Hi all,
I've noticed something that came as a little bit of a surprise to me, but I think I have the explanation, at a hand-wavy higher level anyway.  What I have not established is if this is a 'bug' or a 'feature', and if there are any ways the following issue can be avoided at the NI function/api layer.
Consider the file open and file close function.  You open a file, you use the reference to the file to write/read data, then at some point you close the reference and the close function spits out the file-path.  Here are a couple of tid-bits you may not be aware of (that are easy to test):
Q1) After your application opens/creates a file and starts using the file-reference to make file writes, if an external source changes the file-name of that file... guess what will happen on your next write function call?
A1::  The write successfully updates the newly re-named file with your new data without producing an error or a warning.  (At least this is the case if your program is running on a vxWorks cRIO target and the file-name is changed directly on the cRIO via an FTP browser.)  
Did this surprise you? It did surprise me!  -My handwavy explanation is that the file-pointer is perhaps managed/maintained by the OS, so when the OS tells the file-system to rename that file, the pointer that LabVIEW holds remains valid and the contents of the memory at the pointer location was updated by the OS.
Q2) Continuing from the situation setup in Q1, after writing several new chunks of data to a file now currently named something completely different than when the file reference was originally created, you use the close function to close the file-reference.  What do you expect on the file-path output from the close function??  What do you actually get??
A2::  The close function will 'happily' return the ORIGINAL file-name, not the actual file-name it has been successfully writing to(!).   This has some potentially significant ramifications on how/what you can use that output for.  At this point there is a ton of room for pontifications and more or less 'crazy' schemes for what one could do, but I argue that the bottom line is that your application has at that point completely lost the ability to accurately and securely track your file(s).  Yes, you could list a folder and try and 'figure out' if your file-name was re-named during writing and you can in various ways make more or less good 'guesses' on which file you in reality just had open, but you can never really know for sure.
So, what do you guys think?? Is the behavior of returning the (incorrect) original file-path when you close the handle a BUG or a FEATURE??  Would it not be possible for LabVIEW to read back the data contained in the (OS?) pointer location and as needed update the file out path data when it closes a reference?  Should we not EXPECT that this would be the behavior?
Q3)  Again, continuning from the above situation, lets assume we are back at the state in Q1, writing data to a (re)named file.  What happens if the file is deleted by an external process? What happens to the file reference? File function calls using the reference?
A3::  This one is less surprising.  The file reference remains 'valid' (because it is a valid reference), but depending on the file function you are calling, you will get error such as error 6 (binary write reports this), or error 4 (a TDMS write will report this error), etc.  So as long as you don't rely on file ref-num tests to establish if you are good to go with a file-write or file-action, you should be safe to recover in an appropriate way.. Just don't forget to close the file-reference, even if the file is 'gone', the reference will still remain in memory until you 'close' it (with an error)(?I might be wrong about this last part?)
I am not sure if the above is possible on e.g. Windows, Windows would probably prevent you from re-naming a file that has an open file-handle to it, but this is definitley observable on at least vxWorks cRIO targets.  (I don't have PharLap ETS or RTLinux devices so I can't test on those targets.. if you want to test its pretty straigth forward to make a simple test app for it.)
[begin rant-mode related to why I found this out and why this behavior BITES]
There are situations where the above situation could cause some rather annoying issues that, for somewhat contrived reasons related to cRIO file API performance, CPU and memory resource management, are non-trivial to work around.  for example, using the NI "list folder" to listing folders take a very hefty chunk of time at 100% cpu that you cannot break up, so polling/listing folders after every file update (or even on a less regular interval) is a big challenge, and if you are really unlucky (or didn't know any better) and gave the list command in a folder with 1000's of files (as opposed to less than about 100 files), the list will lock your CPU at 100% for 10's of seconds...  Therefore, you might be tempted to maintain your own look-up table of files so that your application can upload/push/transfer and/or delete files as dictated by your application specific conditions... except that only works until some prankster or well-intention person remotes in and starts changing file-names, because then your carefully maintained list of file-names/paths' suddenly fall appart.
[\end rant]
QFang
CLD LabVIEW 7.1 to 2013

Hey guys, thanks for turning out your comments on this thread!
-Deny Access : still able to re-name (and delete) the file via FTP browser (didn't test other file avenues).  I think this is for the same reason that NI vxWorks targets (such as cRIO-9014) do not support the concept of different users with different rights, as such, everyone have access rights to everything at the OS level.  Another issue for me would be that "Deny Access" does not work on TDMS file references, so even if it worked, it would not help me.
--> I strongly suspect that these things are non-issues or issues that can be properly managed, on the new NI LinuxRT targets since (the ftp is disabled by default) it supports user accounts and user restrictions on files/folders.  The controller could simply create the files in a tree where 'nobody else' has write access.
Obviously nobody should mess around with files on a (running) cRIO, but customers don't always do what they are supposed to do.   
As far as the 'resources' or overhead to update the file-refnum with the new information, this would not be needed to be done in a polling fashion, simply, when the file-close function is called, as part of that call it updates its internal register from the pointer data, so this should be a low overhead operation I would think?  If that is a true concern, a boolean input defaulting to not updating or a separate 'advanced close' could be created?
I've included a zip with the LV2013 project and test VI's (one for tdms one for binary) that I've used. nothing fancy, but in the interest of full disclosure.  The snippet is the 'binary file' test vi, in case you just want a quick peak:
Steve Bird's findings of (yet) another behavior on Pharlap systems is also very interesting, I think!!
[EDIT]  JUST TO CLARIFY, on vxWorks, the re-named file keeps being successfully written to, unlike the PharLaps' empty file that Steve Bird found.
QFang
CLD LabVIEW 7.1 to 2013
Attachments:
cRIO Tests.7z ‏30 KB

Similar Messages

  • File Reference and XML

    Hey everyone, i've been working on an mp3 player that runs
    off of xml i have it set up so that for each instance of a song it
    attaches movie clips onto the stage that serves as buttons. I'm
    trying to add a download button so when you click it it will
    download the file. I'm trying to do this with the file reference
    class but i've been working on it for a week with no luck what so
    ever. if anyone has any ideas it would be so greatly appreciated
    heres my code and xml.
    there may be some unnecessary code in there i was messing
    around trying different things.

    Sorry if it wasnt clear. But to be completely truthful i'm
    not sure what it is thats not working. I'm trying to populate the
    file reference by the xml. everything works except when i test the
    movie online when i click the download button the save file opens
    but it says undefined and clicking save does absolutely nothing.
    So my guess is that my problem lies in my file reference to
    the button.
    this part
    var url:String = "_global.download
    _root["downloadbut"+i].onRelease = function() {
    if(!theFileRef.download(url,_global.songname.mp3)) {
    trace("dialog box failed to open.");
    } else {
    trace("dialog box has open.");
    trace(_global.songname
    i was hoping to know if anyone knew how to properly populate
    the file reference with xml.
    Sorry. Hope that is more clear.

  • How to dynamically define a file name and its path in a web application

    Hi, I want to create a simple web application that reads from an XML file and displays the data back to the user. The xml file is created independent of my application on the same machine that the Application Server runs. How can I define my xml file name and/or path to be independent of my code and not hard-coded in my application?

    By an external configurationfile? That can be a propertiesfile, a xml file, an ini file, a plain vanilla txt file, etcetera.

  • How to append a file directory and its contents in a jTextArea

    how will i display the contents of this file and file directory in a jTextArea or ...let's say it will display the content of "c:/AutoArchive2007-05-24.csv" in a jTextarea
    say this file "c:/AutoArchive2007-05-24.csv"contains the ff:details
    user:jeff AutoArchive-Process Started at Thu May 24 15:41:54 GMT+08:00 2007
    and ended at Thu May 24 15:41:54 GMT+08:00 2007
    Message was edited by:
    ryshi1264

    use the append(...) to append data to the text area.

  • File reference and Other ID field in an Invoice

    Hi
    In the invoice, instead of the Purchase order number user would like to populate with Tax Authorities Reference no.
    In german it is called "Aktenzeichen'. Was not able to find in the invoice
    can anyone let me know where can I find this field and one more which is "Other ID"
    thanks

    Hi,
    there's no field like 'Aktenzeichen' - it can be bkpf-xblnr or bseg-xref1 /2/3
    A.

  • The firefox "whats new" page will not go away after a restart. All settings changes in firefox do not stay either. What can I do? I have tried deleting the localstore file also and its a no go.

    This happens with the new version of firefox. We have many computers with new fox on it and not the same problem. only certain ones.

    Your above posted system details show outdated plugin(s) with known security and stability risks.
    *Java Plug-in 1.6.0_10 for Netscape Navigator (DLL Helper)
    Update the [[Java]] plugin to the latest version.
    *http://java.sun.com/javase/downloads/index.jsp (Java Platform: Download JRE)

  • Project File File References

    Does JDeveloper 9.0.4 use absolute or relative file references in its project (.jpr) files, or is it a mixture of the two? I've heard conflicting stories but have personally only ever seen relative references.

    Yes, I've tried this and have gotten a clean compile.  However, the .dll is associated with third party software intended to add controls to a form.  The form does not display in Designer though (extensive stack trace errors) which made me wonder
    whether there is a downside to this approach.

  • Operations on file: Deleting and get size

    Hi,
    I'm triying to delete a file. I use the following code:
    File found = new File (directoryOutputFileWriter+f);
                   boolean deleted = found.delete();But when I execute it the boolean deleted it's always false and the file is not deleted.
    Then I try to get the size of another file in this way:
    File produced = new File(directoryOutputFileWriter+file[0]);
    long size = produced.length();but I receive a null value (the file exists and its dimension is over 0 of course).
    Why?
    How can I solve?
    Thanks, bye bye.

    Hello,
    in my experience the absolute #1 source of astonishment with file operations is loose manual checking (mistyping or misreading).
    I suggest you use those traces:
    File found = new File (directoryOutputFileWriter+f);
    System.out.println("File path is"+found.getAbsolutePath());
    System.out.println("Does this file exists? "+found.exists());
    System.out.println("Is this file really a file? "+found.isFile()); // You may not be able to delete a directory on all platforms
    System.out.println("Is this file deleted now? "+found.delete());#2 is developers not reading the javadoc (that states that delete may not succeed), but I acknowledge you have read it, as you're investigating why it hasn't, and not complaining that it has.
    #3 is people overlooking OS-specific file management. E.g. Unix-Linux-Window file permissions management all may let you read a file but not delete it (with the unices having a richer set of combinations than windows). The rules for directory deletion are different between Unices and Windows. Etc...
    Edited by: jduprez on Jul 5, 2010 9:44 AM
    @Mel: I sometimes wish I was that much connected to my wife's mind ;o)
    @Joachim: nice catch! Loose manual checking indeed (both on my part and on OP's)...

  • How to get the jar file without knowing its name and any class inside it?

    Hello, everybody!
    I would like to know if there's a way to get a reference programatically to the initial jar without knowing its name and any class contained in it. By "initial jar" I mean the jar that was called in the prompt, like this:
    java -jar jarfile.jaror in another way, in a graphical system. To be sincere what I really want is to get a reference to the jar's manifest, but I know if I can get a reference to the jar I can get a reference to its manifest file. Or if you know a way to get the manifest directly, it would also help. So, is there a way to do this?
    Thank you.
    Marcos

    jverd wrote:
    marcos_aps wrote:
    abillconsl wrote:
    Can you be more specific - IOW, can you cite a specific case?Absolutely. I want to access the jar in source code with the java.util.zip.JarFile class, for example.But why? You still haven't provided a use case or explained what you're trying to accomplish. As already pointed out, whatever you're trying to do, this is a brittle solution. If you explain what you're trying to accomplish with this, somebody may be able to suggest a better approach.jverd, I explained for baftos. Anyway, I will try to be more specific. I start my sytem like this, from, say, for example, jar1.jar:
    import br.product.System;
    public static void main(String[] args)
        System.start("NameOfTheSystem");
    }The System class is in util.jar, for example. This jar is used by all systems. I wouldn't like to pass in the name of the system, as above. I would like that the System class could read it from jar1.jar's manifest file. I just would like to have this:
    import br.product.System;
    public static void main(String[] args)
        System.start();
    }It is more elegant and I don't have the name of the system in two places: code and manifest file.
    Marcos

  • I'm taking pictures with iPad and tying to share on face book and its saying error in need 4mg or jpf files what do I need to change

    I'm taking pictures with my iPad and trying to upload on Facebook and its a error saying i need a smaller then 4mp or j? Something file. I just uploaded pictures last week what happened and ow do I I'd this any clues? Thanks

    Lightning is a problem for you because it hooks into Thunderbird at a low level and you need a version compiled for the platform Thunderbird is running on. So you can't do the preferred solution, which is to put your whole profile in a shared folder and have both instances of Thunderbird reference the same profile. (Ditto for Enigmail). Lightning may become an integral part of Thunderbird in an upcoming release, at which point this limitation due to Lightning should disappear.
    And if you can't use a shared profile, you can't set your Lightning, or your Address Book, to share a common set of files. Put another way, the linkage from Thunderbird to its address book files and calendar data is hard-coded, and not exposed where we can adjust it. :-(
    The halfway house is to place your mail stores in a shared place, and use the Local Directory setting in each account's settings to connect to it. They don't need to be in the profile; what's more important in your case is that they are in a folder accessible to both operating systems.
    Look in your profile; everything under Mail and ImapMail needs to be moved out to a shared folder. Note the entries in Thunderbird under Local Directory before you do this, and reconstruct those pathnames in Thunderbird, but adjusted to suit their new locations.
    (You can see here that you need to make many adjustments, one per account, in each instance of Thunderbird, so it's a high-maintenance solution and this is why we don't recommend it when the alternative, moving the whole profile, is possible.)
    I share address books and calendars between Thunderbirds on various computers (and my phone and tablet) by syncing to something in the cloud; Google Contacts and Google Calendar are my choices, using gContactSync and CalDav.
    Having made the break myself some years ago, I'd recommend you break away from Windows. ;-)

  • Same data wire (source and sink are listed as "datalog file reference of") will not connect

    I am trying to write a short program that will convert a string spreadsheet file into a datalog file with the numbers turned back into numbers.  I have a case structure for each type of spreadsheet (different types per columns and different number of columns).  I use a 'for loop' to process all records (rows).  And I use a 'sequence structure' to individually process each column item into its original format (string or number), then group together into a bundle and then write the results to the datalog file format.
    The first two (case structures) worked but the second pair of case structures would not allow me to connect the datalog file reference number from the 'write to datalog file' to the 'close datalog file' through the 'for loop' wall.
    I am using 8.2
    I am sure it is an stupid issue, but the error message just did not point me towards a solution.
    con-fUsed, DogFace.
    Attachments:
    PROCESS SH TO DLOG.vi ‏84 KB

    The problem is that you are creating a different type of datalog file in cases 2 and 3 than you are in cases 0 and 1.
    The structure of a datalog file is the same as an array of clusters. All of the clusters must be of the same structure. Only the values of the individual cluster elements can vary.
    You are trying to write three different cluster structures to a single datalog file. You just can't this.
    You'll either need to write to three different files, or come up with a structure that everything will fit into.
    One other quick hint. NEVER use a variable to pass data when you can wire the terminal directly to the function.
    Ed
    Message Edited by Ed Dickens on 03-19-2007 11:39 AM
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.

  • Why does FCP looses its source file reference when files are copied

    Why does FCP looses its source file reference when files are copied from another project??
    i have this happen all the time, I move all my media to another drive and files that originated in another project do not reconnect because they have lost there source?
    Any way to fix this mess? i am in the middle of reconnecting 400 files by hand one at a time!!!
    Thanks, mark

    Because you changed the file path. From one hard drive to another...the hard drive name is no doubt different, and then if you have the files in different folder structures then yeah, it will lose the connection to that media.
    Best thing to do is to clone your media drive, or name the other drive the same name, and keep the exact same file structure (folders in folders) as the original drive. Then you won't need to reconnect.
    Shane

  • I also have a .csv file with the name of a jpeg in one column and a text description of each jpeg in a second column. Is there a way to automatically insert one jpeg (photo) and its corresponding text, each pair on one page, into a Indesign document?

    I also have a .csv file with the name of a jpeg in one column and a text description of each jpeg in a second column. Is there a way to automatically insert one jpeg (photo) and its corresponding text, each pair on one page, into a Indesign document?

    I would also recommend to write the description into the meta data. This would allow to place a text frame above the image and it is possible to add meta information and file name automatically together with the image, when you place it or even in a prepared template.
    Meta data information can be written easily in Bridge in the Meta File Workspace.

  • How to remove a font file and its mapping from XML Publisher Administrator

    Hello,
    I am trying to remove a font file and its mapping from the XML Publisher Administrator. If this is not possible, is there a way to disable it?
    The reason why I am asking this is because we just got a new check printer, and I was able to print just fine. However, the MICR font was not coming up properly on the check, so I went ahead and configured the font with the XML Publisher Administrator. Now my check output is coming up blank after running the XML report publisher program. The only change I did was to upload the MICR font and mapped it.
    My template and rdf report file are working fine in another environment we have, so I know that's not the problem.
    Any help is appreciate it.
    Thanks.

    This is how you do it
    Font
    DELETE FROM xdo_lobs
    where lob_code like '<Font_name>';
    Font Mapping Set
    DELETE FROM xdo_font_mapping_sets_TL
    WHERE mapping_code like '<MAPPING_CODE>'

  • I purchased a song on itunes and its file can not be located. its in my library but i cant play the song

    I purchased a song on itunes and its file can not be located. Its listed in my library but can not play. A message pops up that read. Can not locate file then it gives me an option to locate. When I click locate it opens a box. Dont know what to do after that

    Hi TKCDM1!
    You should try to get this purchase onto your iOS device by using the suggestions in the following article:
    Downloading past purchases from the iTunes Store, App Store, and iBooks Store
    http://support.apple.com/kb/ht2519
    Thanks for being a part of the Apple Support Communities!
    Regards,
    Braden

Maybe you are looking for

  • Report on AB / LA confirmed POs along with values

    Hi, How to get the report on list of Purchase Orders that have AB confirmations along with values. How to get the report on list of Purchase Orders that have LA confirmations along with values. Kindly help. Regards, Vengat

  • HT5544 How do I get at least the covers to show up in their collections on ipad?

    I have set preferences to sync everything in both  ibooks on ipad and on desktop and I am using the same apple id on both devices but my 3rd party epubs and pdfs are not all showing on my ipad. How do I get at least the covers to show up in their col

  • SQL Server Reporting Services Native Mode: SSRS 2012 vs SSRS 2014

    Hi, I'm looking at getting my servers upgraded to SQL Server 2014.  My SSRS reporting server is SQL 2012 native mode. I know there were not really any significant enhancements in native mode going from SSRS 2008 R2 to SSRS 2012.  Does SSRS 2014 add a

  • Pictures load on all other browsers but not safari

    Hi, For some reason when I view my virtual tour webpages on safari the thumbnails on the bottom bar don't load first time. I need to refresh the page (but this doesn't work every time) or re enter the web address to get the thumbnails to appear. I do

  • How to cancel row insertion by trigger?

    Hello, everybody! I need the trigger that supplies following functionality: If UID (unique constrained)is already in some row, it updates the line where UID = :NEW.UID instead of inserting new one incrementing INDEXCOUNTER in this row. The table is l