Menu

#2438 Simpler temp file class

Trunk
closed-accepted
5
2008-01-18
2008-01-17
Kimmo Varis
No

It was error to create TempFileContext class. Yes it made handling MergeDoc temp files simpler, but it just cannot be used elsewhere. And it is just too complex for the simple task it has.

So I created simpler TempFile class which just holds one temp file path. And deletes the temp file when instance gets deleted.

TempFile can (and should) be used everywhere we use temp files to make sure we delete all our temp files.

Discussion

  • Kimmo Varis

    Kimmo Varis - 2008-01-17

    Original and altered files.

     
  • Kimmo Varis

    Kimmo Varis - 2008-01-18

    Updated patch.

     
  • Kimmo Varis

    Kimmo Varis - 2008-01-18

    Logged In: YES
    user_id=631874
    Originator: YES

    Found regression from first patch. There was some weird code that in original form copied temp *files* not just paths or filenames from mergedoc to buffer code. I don't know any reason for such trick so I just removed that. In a kind of replacement I added code for TempFile class to behave similarly by creating a temp file from given file.

    Attaching updated patch.
    File Added: SimplerTempfiles2.zip

     
  • Kimmo Varis

    Kimmo Varis - 2008-01-18
    • assigned_to: nobody --> kimmov
    • status: open --> closed-accepted
     
  • Kimmo Varis

    Kimmo Varis - 2008-01-18

    Logged In: YES
    user_id=631874
    Originator: YES

    Committed to SVN trunk.
    Completed: At revision: 4929

     
  • Takashi Sawanaka

    Logged In: YES
    user_id=954028
    Originator: NO

    This patch causes crash when clicking [File]->[New] menu item.

    I think the following fix from the analogy of old TempFileContext::CreateFiles() solves this problem.

    Index: TempFile.cpp

    --- TempFile.cpp (revision 4937)
    +++ TempFile.cpp (working copy)
    @@ -77,10 +77,10 @@
    temp = env_GetTempFileName(temp.c_str(), pref.c_str(), NULL);
    if (!temp.empty())
    {
    + m_path = temp;
    if (::CopyFile(filepath, temp.c_str(), FALSE))
    {
    ::SetFileAttributes(temp.c_str(), FILE_ATTRIBUTE_NORMAL);
    - m_path = temp;
    }
    }
    return temp;

     
  • Kimmo Varis

    Kimmo Varis - 2008-01-22

    Logged In: YES
    user_id=631874
    Originator: YES

    I'm not sure I like the original logic (even when it was my too). Function's idea is to copy existing file data to used as temp file. So it should succeed only when we really copy the data.

    But, scratchpads are again a special case I'm not sure how to handle.

    So I think your is good as it fixes the bug (of course!) but I just hope we'd have better logic for handling scratchpads than adding special cases in so many places.

     
  • Kimmo Varis

    Kimmo Varis - 2008-01-22

    Logged In: YES
    user_id=631874
    Originator: YES

    I committed your patch to SVN trunk with comment about scratchpads.
    Completed: At revision: 4943

     

Log in to post a comment.