octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #56298] [Windows] File Browser "rename" operat


From: Rik
Subject: [Octave-bug-tracker] [bug #56298] [Windows] File Browser "rename" operation deletes file when only changing case of file name
Date: Mon, 13 May 2019 12:05:08 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

Update of bug #56298 (project octave):

                  Status:               Need Info => Confirmed              
                 Summary: File deleted when renaming => [Windows] File Browser
"rename" operation deletes file when only changing case of file name

    _______________________________________________________

Follow-up Comment #3:

Thanks.  I changed the Summary to more accurately describe the problem. 
Marking as Confirmed, althoug I can only test on a Linux platform where this
works.

The issue is going to be in libgui/src/files-dock-widget.cc.


  void files_dock_widget::contextmenu_rename (bool)
  {
    QItemSelectionModel *m = m_file_tree_view->selectionModel ();
    QModelIndexList rows = m->selectedRows ();
    if (rows.size () > 0)
      {
        QModelIndex index = rows[0];

        QFileInfo info = m_file_system_model->fileInfo (index);
        QDir path = info.absoluteDir ();
        QString old_name = info.fileName ();
        bool ok;

        QString new_name
          = QInputDialog::getText (this, tr ("Rename file/directory"),
                                   tr ("Rename file/directory:\n")
                                   + old_name + tr ("\n to: "),
                                   QLineEdit::Normal, old_name, &ok);
        if (ok && new_name.length () > 0)
          {
            new_name = path.absolutePath () + '/' + new_name;
            old_name = path.absolutePath () + '/' + old_name;
            // editor: close old
            emit file_remove_signal (old_name, new_name);
            // Do the renaming
            bool st = path.rename (old_name, new_name);
            // editor: load new/old file depending on success
            emit file_renamed_signal (st);
            // Clear cache of file browser
            m_file_system_model->revert ();
          }
      }

  }


We are using Qt's rename function from the Qdir class.  The documentation for
that is


bool QDir::rename(const QString &oldName, const QString &newName)

Renames a file or directory from oldName to newName, and returns true if
successful; otherwise returns false.

On most file systems, rename() fails only if oldName does not exist, or if a
file with the new name already exists. However, there are also other reasons
why rename() can fail. For example, on at least one file system rename() fails
if newName points to an open file.

If oldName is a file (not a directory) that can't be renamed right away, Qt
will try to copy oldName to newName and remove oldName.

See also QFile::rename().


It seems possible that Qt is trying to copy oldName to newName, which probably
fails on Windows when the file name only differs by case, and then instead of
aborting it goes on to remove oldName. 

That could be tested in a stand-alone Qt program.

Actually, a little more Google digging shows that this is a known error for Qt
versions less than 5.10.  See https://bugreports.qt.io/browse/QTBUG-3570.

What version of Qt does MXE-Octave version 5.1.0 ship with?

Adding John D. to the CC list for the answer to the last question.



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?56298>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]