Home Download Buy Blog Forum Support

[BUG]: Data erasure on session restore

[BUG]: Data erasure on session restore

Postby ketura on Sun Jun 03, 2012 7:08 pm

For a bit of background, I'm on a Linux Mint 13 x64 system and just barely installed sublime (a fantastic feature set, btw, I'm very impressed). My experience with the program has unfortunately been marred by an unfortunate data loss bug, which I have been able to reproduce exactly and have caused crashes while attempting, so hopefully this is helpful:

This is using an NTFS-formatted file system, btw, have not tested with ext3/4.

1- Make sure "remember_open_files": true, in the active settings

2- Save a text file

3- Close Sublime, thus saving session data

4- Unmount the drive (which I did initially via restarting, but manual unmounting also delivers)

5- Open Sublime, restoring the session, including files that cannot be opened on the unmounted drive. These files will show as blank in the editor but there will otherwise be no indication that anything is wrong or that the files failed to load.

6- Mount the drive. If you look at the applicable files in Nautilus (or the file system viewer of your choice) you will see that the file still exists and the data is still intact.

7- Give those same files focus within Sublime. A popup will appear, stating the files have changed, would you like to reload this file or cancel? regardless of whichever option you choose, Sublime will attempt to load the file, fail to do so, and then show the blank file once more. Again, there is no indication that anything wrong has happened. However, the file has now been wiped to 0 bytes, reflecting the actual blank file in Sublime's display.


I'm sorry to say that I lost a ~300 line python script I've worked on all week as well as the files it was meant to process and export. This is of course my fault for not using version control (though you can be sure that's never a pitfall I'll ever fall for again), but still, I should have been told initially that my files didn't load, or perhaps a version could be kept in Sublime's collective memory, a la Notepad++, or something to that effect.

I'll include here a copy of my default Preferences.sublime-settings (which is the one I've modified) in case there's a conflict with another of the options.

Code: Select all
// While you can edit this file, it's best to put your changes in
// "User/Preferences.sublime-settings", which overrides the settings in here.
//
// Settings may also be placed in file type specific options files, for
// example, in Packages/Python/Python.sublime-settings for python files.
{
    // Sets the colors used within the text area
    "color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",

    // Note that the font_face and font_size are overriden in the platform
    // specific settings file, for example, "Preferences (Linux).sublime-settings".
    // Because of this, setting them here will have no effect: you must set them
    // in your User File Preferences.
    "font_face": "",
    "font_size": 10,

    // Valid options are "no_bold", "no_italic", "no_antialias", "gray_antialias",
    // "subpixel_antialias" and "no_round" (OS X only)
    "font_options": [],

    // Characters that are considered to separate words
    "word_separators": "./\\()\"'-:,.;<>~!@#$%^&*|+=[]{}`~?",

    // Set to false to prevent line numbers being drawn in the gutter
    "line_numbers": true,

    // Set to false to hide the gutter altogether
    "gutter": true,

    // Spacing between the gutter and the text
    "margin": 4,

    // Fold buttons are the triangles shown in the gutter to fold regions of text
    "fold_buttons": true,

    // Hides the fold buttons unless the mouse is over the gutter
    "fade_fold_buttons": true,

    // Columns in which to display vertical rulers
    "rulers": [],

    // Set to true to turn spell checking on by default
    "spell_check": false,

    // The number of spaces a tab is considered equal to
    "tab_size": 4,

    // Set to true to insert spaces when tab is pressed
    "translate_tabs_to_spaces": true,

    // If translate_tabs_to_spaces is true, use_tab_stops will make tab and
    // backspace insert/delete up to the next tabstop
    "use_tab_stops": true,

    // Set to false to disable detection of tabs vs. spaces on load
    "detect_indentation": true,

    // Calculates indentation automatically when pressing enter
    "auto_indent": true,

    // Makes auto indent a little smarter, e.g., by indenting the next line
    // after an if statement in C. Requires auto_indent to be enabled.
    "smart_indent": true,

    // Adds whitespace up to the first open bracket when indenting. Requires
    // auto_indent to be enabled.
    "indent_to_bracket": true,

    // Trims white space added by auto_indent when moving the caret off the
    // line.
    "trim_automatic_white_space": true,

    // Disables horizontal scrolling if enabled.
    // May be set to true, false, or "auto", where it will be disabled for
    // source code, and otherwise enabled.
    "word_wrap": "auto",

    // Set to a value other than 0 to force wrapping at that column rather than the
    // window width
    "wrap_width": 0,

    // Set to false to prevent word wrapped lines from being indented to the same
    // level
    "indent_subsequent_lines": true,

    // Draws text centered in the window rather than left aligned
    "draw_centered": false,

    // Controls auto pairing of quotes, brackets etc
    "auto_match_enabled": true,

    // Word list to use for spell checking
    "dictionary": "Packages/Language - English/en_US.dic",

    // Set to true to draw a border around the visible rectangle on the minimap.
    // The color of the border will be determined by the "minimapBorder" key in
    // the color scheme
    "draw_minimap_border": false,

    // If enabled, will highlight any line with a caret
    "highlight_line": true,

    // Valid values are "smooth", "phase", "blink", "wide" and "solid".
    "caret_style": "smooth",

    // Set to false to disable underlining the brackets surrounding the caret
    "match_brackets": true,

    // Set to false if you'd rather only highlight the brackets when the caret is
    // next to one
    "match_brackets_content": true,

    // Set to false to not highlight square brackets. This only takes effect if
    // match_brackets is true
    "match_brackets_square": true,

    // Set to false to not highlight curly brackets. This only takes effect if
    // match_brackets is true
    "match_brackets_braces": true,

    // Set to false to not highlight angle brackets. This only takes effect if
    // match_brackets is true
    "match_brackets_angle": false,

    // Enable visualization of the matching tag in HTML and XML
    "match_tags": true,

    // Highlights other occurrences of the currently selected text
    "match_selection": true,

    // Additional spacing at the top of each line, in pixels
    "line_padding_top": 0,

    // Additional spacing at the bottom of each line, in pixels
    "line_padding_bottom": 0,

    // Set to false to disable scrolling past the end of the buffer.
    // On OS X, this value is overridden in the platform specific settings, so
    // you'll need to place this line in your user settings to override it.
    "scroll_past_end": true,

    // This controls what happens when pressing up or down when on the first
    // or last line.
    // On OS X, this value is overridden in the platform specific settings, so
    // you'll need to place this line in your user settings to override it.
    "move_to_limit_on_up_down": false,

    // Set to "none" to turn off drawing white space, "selection" to draw only the
    // white space within the selection, and "all" to draw all white space
    "draw_white_space": "selection",

    // Set to false to turn off the indentation guides.
    // The color and width of the indent guides may be customized by editing
    // the corresponding .tmTheme file, and specifying the colors "guide",
    // "activeGuide" and "stackGuide"
    "draw_indent_guides": true,

    // Controls how the indent guides are drawn, valid options are
    // "draw_normal" and "draw_active". draw_active will draw the indent
    // guides containing the caret in a different color.
    "indent_guide_options": ["draw_normal"],

    // Set to true to removing trailing white space on save
    "trim_trailing_white_space_on_save": true,

    // Set to true to ensure the last line of the file ends in a newline
    // character when saving
    "ensure_newline_at_eof_on_save": false,

    // Set to true to automatically save files when switching to a different file
    // or application
    "save_on_focus_lost": true,

    // The encoding to use when the encoding can't be determined automatically.
    // ASCII, UTF-8 and UTF-16 encodings will be automatically detected.
    "fallback_encoding": "Western (Windows 1252)",

    // Encoding used when saving new files, and files opened with an undefined
    // encoding (e.g., plain ascii files). If a file is opened with a specific
    // encoding (either detected or given explicitly), this setting will be
    // ignored, and the file will be saved with the encoding it was opened
    // with.
    "default_encoding": "UTF-8",

    // Files containing null bytes are opened as hexadecimal by default
    "enable_hexadecimal_encoding": true,

    // Determines what character(s) are used to terminate each line in new files.
    // Valid values are 'system' (whatever the OS uses), 'windows' (CRLF) and
    // 'unix' (LF only).
    "default_line_ending": "system",

    // When enabled, pressing tab will insert the best matching completion.
    // When disabled, tab will only trigger snippets or insert a tab.
    // Shift+tab can be used to insert an explicit tab when tab_completion is
    // enabled.
    "tab_completion": true,

    // Enable auto complete to be triggered automatically when typing.
    "auto_complete": true,

    // The maximum file size where auto complete will be automatically triggered.
    "auto_complete_size_limit": 4194304,

    // The delay, in ms, before the auto complete window is shown after typing
    "auto_complete_delay": 50,

    // Controls what scopes auto complete will be triggered in
    "auto_complete_selector": "source - comment",

    // Additional situations to trigger auto complete
    "auto_complete_triggers": [ {"selector": "text.html", "characters": "<"} ],

    // By default, auto complete will commit the current completion on enter.
    // This setting can be used to make it complete on tab instead.
    // Completing on tab is generally a superior option, as it removes
    // ambiguity between committing the completion and inserting a newline.
    "auto_complete_commit_on_tab": false,

    // Controls if auto complete is shown when snippet fields are active.
    // Only relevant if auto_complete_commit_on_tab is true.
    "auto_complete_with_fields": false,

    // By default, shift+tab will only unindent if the selection spans
    // multiple lines. When pressing shift+tab at other times, it'll insert a
    // tab character - this allows tabs to be inserted when tab_completion is
    // enabled. Set this to true to make shift+tab always unindent, instead of
    // inserting tabs.
    "shift_tab_unindent": true,

    // If true, the selected text will be copied into the find panel when it's
    // shown.
    // On OS X, this value is overridden in the platform specific settings, so
    // you'll need to place this line in your user settings to override it.
    "find_selected_text": true,

    //
    // User Interface Settings
    //

    // The theme controls the look of Sublime Text's UI (buttons, tabs, scroll bars, etc)
    "theme": "Default.sublime-theme",

    // Set to 0 to disable smooth scrolling. Set to a value between 0 and 1 to
    // scroll slower, or set to larger than 1 to scroll faster
    "scroll_speed": 1.0,

    // Controls side bar animation when expanding or collapsing folders
    "tree_animation_enabled": true,

    "show_tab_close_buttons": true,

    // OS X 10.7 only: Set to true to disable Lion style full screen support.
    // Sublime Text must be restarted for this to take effect.
    "use_simple_full_screen": false,

    // Valid values are "system", "enabled" and "disabled"
    "overlay_scroll_bars": "system",

    //
    // Application Behavior Settings
    //

    // Exiting the application with hot_exit enabled will cause it to close
    // immediately without prompting. Unsaved modifications and open files will
    // be preserved and restored when next starting.
    //
    // Closing a window with an associated project will also close the window
    // without prompting, preserving unsaved changes in the workspace file
    // alongside the project.
    "hot_exit": true,

    // remember_open_files makes the application start up with the last set of
    // open files. Changing this to false will have no effect if hot_exit is
    // true
    "remember_open_files": true,

    // OS X only: When files are opened from finder, or by dragging onto the
    // dock icon, this controls if a new window is created or not.
    "open_files_in_new_window": true,

    // Set to true to close windows as soon as the last file is closed, unless
    // there's a folder open within the window. This is always enabled on OS X,
    // changing it here won't modify the behavior.
    "close_windows_when_empty": false,

    // folder_exclude_patterns and file_exclude_patterns control which files
    // are listed in folders on the side bar. These can also be set on a per-
    // project basis.
    "folder_exclude_patterns": [".svn", ".git", ".hg", "CVS"],
    "file_exclude_patterns": ["*.pyc", "*.pyo", "*.exe", "*.dll", "*.obj","*.o", "*.a", "*.lib", "*.so", "*.dylib", "*.ncb", "*.sdf", "*.suo", "*.pdb", "*.idb", ".DS_Store", "*.class", "*.psd", "*.db"],
    // These files will still show up in the side bar, but won't be included in
    // Goto Anything or Find in Files
    "binary_file_patterns": ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip"],

    // List any packages to ignore here. When removing entries from this list,
    // a restart may be required if the package contains plugins.
    "ignored_packages": ["Vintage"]
}



Thank you for your time, and thanks for what otherwise appears to be a fantastic editor!
ketura
 
Posts: 3
Joined: Sun Jun 03, 2012 6:38 pm

Re: [BUG]: Data erasure on session restore

Postby Bjoern on Tue Jul 17, 2012 10:05 pm

Hi,

I just had the same problem unfortunately, resulting in an empty file. After the mounted drive failed to answer (disconnect) a save in sublime gave me the popup "Unable to save to ... ". I quit sublime and after I remounted the drive and opened the file it was empty.

No I have set
"hot_exit": false,
"remember_open_files": false

Hopefully this will prevent the problem from occurring again.
Bjoern
 
Posts: 1
Joined: Tue Jul 17, 2012 10:00 pm

Re: [BUG]: Data erasure on session restore

Postby quodlibet on Wed Jul 18, 2012 12:08 pm

I've also experienced this issue (or something very similar) on Windows with files saved on a USB stick. Rather stupidly, the files I've lost (more than once) were my todo list & related notes. Imagine beginning a todo list with the line:

Code: Select all
reconstruct todo list from memory


:evil:

I've since put them in Dropbox. A fix would be nice as I expect I will come across this issue again.
quodlibet
 
Posts: 498
Joined: Sat Jun 18, 2011 5:53 pm

Re: [BUG]: Data erasure on session restore

Postby PuddingDog on Fri Aug 10, 2012 3:36 am

Hi all,

I can confirm that this data loss bug still exists on release 2.0.1:

Here's how to reproduce (on a Mac):

0. in user pref, set save_on_focus_lost to true
1. connect an external drive or mount a network share
2. create and save a file on the ext. drive (do not close the tab)
3. CMD+Q ST2
4. Eject / Unmount the ext drive
5. launch ST2
6. now you will see the tab re-opened with an empty file of the same name
7. connect the ext drive
8. CMD+TAB to another app
9. return to ST2, now the file has been truncated / overwritten!
PuddingDog
 
Posts: 4
Joined: Tue Nov 29, 2011 2:36 am

Re: [BUG]: Data erasure on session restore

Postby perfectm on Wed Aug 15, 2012 4:58 pm

Until this bug is fixed, can we be certain what preferences should NOT be set. All of my code is on an NTFS mounted drive, and everytime my laptop wakes from sleep it has a chance that I need to re-mount the drive. I just lost 3 files worth of SAS code. Alas i had a recent back up, but without it would have been completely lost.
perfectm
 
Posts: 1
Joined: Wed Aug 15, 2012 4:57 pm

Re: [BUG]: Data erasure on session restore

Postby Tuanglen on Wed Aug 22, 2012 9:13 pm

This one almost bit me, too.

I just noticed that ST2 still has one of my docs open in a minimized window, a doc that it loaded from an external drive that is no longer connected. I probably unmounted the drive during a period when ST2 wasn't running then restarted ST2 later, which tried to reload my files (which normally I prefer). The document in the window used to contain a lot of code when I first opened it, but now it is empty. If this version were to get saved somehow, I would lose my code. Fortunately, I remembered reading about this bug here in this forum, so I can take steps to make sure that ST2 doesn't nuke the original file the next time I connect the drive.

I'm just starting to evaluate ST2 and already it seems it will pose a serious risk to files on external drives. I could try to not ever use it on files unless they were on the internal drive, but double clicking a file on an external drive would still open it with ST2 if I let ST2 be my standard code editor. I could tell ST2 not to reopen files when it starts up, but it's possible that the drive might get unmounted somehow while ST2 is still running, so that might not keep the file from being zeroed and then written out to the drive when it is remounted.

I could be wrong about any of these speculations, but I think I'll wait on my evaluation of ST2 until I see how this issue is dealt with.
Tuanglen
 
Posts: 15
Joined: Wed Aug 22, 2012 8:17 am

Re: [BUG]: Data erasure on session restore

Postby madnomad on Wed Aug 22, 2012 9:38 pm

The problem is some people not thinking about the implications of turning on the "save_on_focus_lost" option.
If you leave that off, the only risk left is human error but that one is always there anyway.
madnomad
 
Posts: 18
Joined: Tue Aug 14, 2012 8:34 pm

Re: [BUG]: Data erasure on session restore

Postby Tuanglen on Thu Aug 23, 2012 1:13 am

FWIW, I have remember_open_files set to true and save_on_focus_lost set to false. In other words, I appear to have the same settings as the first poster in this thread. I did NOT lose any data, though I would have if ST2 had been allowed to save. According to the first post, there may be circumstances in which ST2 would save this ruined file whether I asked it to do so or not. I have NOT attempted to repeat that poster's final steps, but Step 7 sounds pretty ominous.

At the very least, I can verify that ST2 can delete the contents of your file and pretend that it is just the latest version you have created. Anything that results in the saving of that file will destroy data. I suggest that any file editor that fails to load a file should not pretend to have loaded it. Instead of inventing a bad version of the file and offering multiple ways to save it on top of the good version (incl. accidentally and automatically), it should say, "Can't read file: /such/and/such.py". If it really can't read anything into memory, then there's no point in allowing saving. Just close the window for that file. If the drive became unmounted while the window was open, and there were edits in the buffer that weren't saved, offer a "Save as..." option. If the data in the buffer is lost, don't allow the empty file to be saved on top of the good file.
Tuanglen
 
Posts: 15
Joined: Wed Aug 22, 2012 8:17 am

Re: [BUG]: Data erasure on session restore

Postby madnomad on Thu Aug 23, 2012 2:34 am

Tuanglen wrote:FWIW, I have remember_open_files set to true and save_on_focus_lost set to false. In other words, I appear to have the same settings as the first poster in this thread. I did NOT lose any data, though I would have if ST2 had been allowed to save. According to the first post, there may be circumstances in which ST2 would save this ruined file whether I asked it to do so or not. I have NOT attempted to repeat that poster's final steps, but Step 7 sounds pretty ominous.

Actually OP had save_on_focus_lost enabled if you check his user preferences.
And from what I gather that is the only case in which ST2 takes the liberty of saving a buffer into file.
Blaming that on session restore seems to be just a misunderstanding on his part.

Personally I hate when text editors start throwing dialog boxes in my face for every missing file when loading a session, and I'm glad that ST doesn't follow that trend. Automatically closing failed buffers might not always be what I want either.
I can agree that ideally ST should set error flag on any buffer that failed to load and make the auto save to skip such buffers. And clear the error state only after successful reload with user interaction.
I don't understand why ST saves the empty buffer back into file upon user activating that view, right before showing the dialog informing that file has changed on disk and asking if user wants to reload it. That's just retarded and should be fixed.

But then again, this save_on_focus_lost setting isn't preferable most of the time and, by its definition, pretty dangerous to begin with even if implemented correctly. There's a good reason why it's disabled by default. Anyone who doesn't get a huge warning signal light up in his head when stumbling upon it kinda deserves what's coming to him. Some people only learn the hard way.
madnomad
 
Posts: 18
Joined: Tue Aug 14, 2012 8:34 pm

Re: [BUG]: Data erasure on session restore

Postby Tuanglen on Thu Aug 23, 2012 3:21 am

Personally I hate when text editors start throwing dialog boxes in my face for every missing file when loading a session, and I'm glad that ST doesn't follow that trend. Automatically closing failed buffers might not always be what I want either.


Pretending that you have successfully opened a file and inventing contents for it is unacceptable. If you can't open it, don't open it. If it's already opened but you lose contact with the drive it's stored on, you ought to say something about the problem. You don't have to automatically close it, but you shouldn't just pretend that everything is fine.

I can agree that ideally ST should set error flag on any buffer that failed to load and make the auto save to skip such buffers. And clear the error state only after successful reload with user interaction.


We agree on this.

I don't understand why ST saves the empty buffer back into file upon user activating that view, right before showing the dialog informing that file has changed on disk and asking if user wants to reload it. That's just retarded and should be fixed.


And on this. So true.

But then again, this save_on_focus_lost setting isn't preferable most of the time and, by its definition, pretty dangerous to begin with even if implemented correctly. There's a good reason why it's disabled by default.


I really like the tendency of most new Apple apps and Google Docs to autosave essentially on every keystroke, but you have to have other sensible features to make it safe. For one, you need a lot of undo power. Whether you spill coffee on your keyboard and discover new keyboard shortcuts, the machine crashes, the app crashes, someone trips on the USB cable and "unmounts" your drive, you lose your net connection, or whatever, when you get back in touch with your file, your file will probably be fine, but if it's not, you can undo it to a recent valid state. Also, if you have a local buffer that gets detached from the saved copy, you do what you wisely suggest with regard to setting an error flag that requires some attention.
Tuanglen
 
Posts: 15
Joined: Wed Aug 22, 2012 8:17 am

Next

Return to Technical Support

Who is online

Users browsing this forum: Yahoo [Bot] and 22 guests