Bug 445500

Summary: Saving file fails if a backup file exists with brackets in the filename
Product: [Frameworks and Libraries] frameworks-kcoreaddons Reporter: Franck Rabeson <rabeson.franck>
Component: generalAssignee: Michael Pyne <mpyne>
Status: REOPENED ---    
Severity: normal CC: halla, kdelibs-bugs
Priority: NOR    
Version: 5.98.0   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In:

Description Franck Rabeson 2021-11-14 20:17:36 UTC
STEPS TO REPRODUCE
1. Create file with brackets [] in the name.
2. Save at least once so a backup file exists.
3. Try to save again.

OBSERVED RESULT
Krita fails to overwrite the existing backup and fails to save the opened file.

EXPECTED RESULT
The backup is overwritten and the file is saved.

SOFTWARE/OS VERSIONS
Windows: 10 x64 v2104

ADDITIONAL INFORMATION
Comment 1 Franck Rabeson 2021-11-14 20:18:59 UTC
Tested in: git d2f29d7
Comment 2 Halla Rempt 2021-11-16 10:23:28 UTC
I've tested this in the latest nightly build, on Windows and Linux, with the filename bla[].kra, and I cannot reproduce the issue. Can you please attach the system information contents of Help->Report Bug to this bug?
Comment 3 sh_zam 2021-11-16 15:13:12 UTC
This looks similar to the encoding issues we had on Android. I wonder if the
file manager by any chance returns an encoded path?
Comment 4 Franck Rabeson 2021-11-16 18:22:51 UTC
(In reply to Halla Rempt from comment #2)
> I've tested this in the latest nightly build, on Windows and Linux, with the
> filename bla[].kra, and I cannot reproduce the issue. Can you please attach
> the system information contents of Help->Report Bug to this bug?

I've set up Krita so it keeps 5 backups of each file in the same folder as the original file, with .bak as the extension.

I just reproduced the bug on my machine. Here's the log:

Krita

 Version: 5.1.0-prealpha (git 4807d9c)
 Languages: en_US, en, en_US, en, en_US, en, en_US, en, fr_FR, fr, en_US, en
 Hidpi: false

Qt

  Version (compiled): 5.12.11
  Version (loaded): 5.12.11

OS Information

  Build ABI: x86_64-little_endian-llp64
  Build CPU: x86_64
  CPU: x86_64
  Kernel Type: winnt
  Kernel Version: 10.0.19043
  Pretty Productname: Windows 10 (10.0)
  Product Type: windows
  Product Version: 10

OpenGL Info
 
  Vendor:  "Google Inc." 
  Renderer:  "ANGLE (Radeon RX 580 Series Direct3D11 vs_5_0 ps_5_0)" 
  Version:  "OpenGL ES 3.0 (ANGLE 2.1.0.57ea533f79a7)" 
  Shading language:  "OpenGL ES GLSL ES 3.00 (ANGLE 2.1.0.57ea533f79a7)" 
  Requested format:  QSurfaceFormat(version 3.0, options QFlags<QSurfaceFormat::FormatOption>(DeprecatedFunctions), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples -1, swapBehavior QSurfaceFormat::DoubleBuffer, swapInterval 0, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::CompatibilityProfile) 
  Current format:  QSurfaceFormat(version 3.0, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8, alphaBufferSize 8, stencilBufferSize 8, samples 0, swapBehavior QSurfaceFormat::DefaultSwapBehavior, swapInterval 0, colorSpace QSurfaceFormat::DefaultColorSpace, profile  QSurfaceFormat::NoProfile) 
     Version: 3.0
     Supports deprecated functions false 
     is OpenGL ES: true 
  supportsBufferMapping: true 
  supportsBufferInvalidation: false 
  Extensions: 
     "GL_EXT_read_format_bgra" 
     "GL_OES_compressed_ETC1_RGB8_texture" 
     "GL_OES_rgb8_rgba8" 
     "GL_CHROMIUM_copy_compressed_texture" 
     "GL_OES_element_index_uint" 
     "GL_CHROMIUM_bind_uniform_location" 
     "GL_OES_EGL_image_external" 
     "GL_EXT_texture_filter_anisotropic" 
     "GL_ANGLE_client_arrays" 
     "GL_ANGLE_framebuffer_blit" 
     "GL_EXT_draw_buffers" 
     "GL_EXT_map_buffer_range" 
     "GL_CHROMIUM_sync_query" 
     "GL_ANGLE_pack_reverse_row_order" 
     "GL_EXT_texture_storage" 
     "GL_EXT_frag_depth" 
     "GL_EXT_color_buffer_half_float" 
     "GL_KHR_debug" 
     "GL_EXT_robustness" 
     "GL_EXT_texture_compression_s3tc_srgb" 
     "GL_ANGLE_translated_shader_source" 
     "GL_CHROMIUM_color_buffer_float_rgb" 
     "GL_CHROMIUM_copy_texture" 
     "GL_EXT_shader_texture_lod" 
     "GL_OES_texture_half_float" 
     "GL_NV_pack_subimage" 
     "GL_EXT_texture_rg" 
     "GL_OES_get_program_binary" 
     "GL_EXT_discard_framebuffer" 
     "GL_OES_texture_float" 
     "GL_NV_EGL_stream_consumer_external" 
     "GL_EXT_occlusion_query_boolean" 
     "GL_ANGLE_instanced_arrays" 
     "GL_EXT_texture_norm16" 
     "GL_ANGLE_request_extension" 
     "GL_ANGLE_texture_compression_dxt5" 
     "" 
     "GL_EXT_blend_minmax" 
     "GL_OES_vertex_array_object" 
     "GL_ANGLE_texture_usage" 
     "GL_CHROMIUM_color_buffer_float_rgba" 
     "GL_ANGLE_depth_texture" 
     "GL_ANGLE_texture_compression_dxt3" 
     "GL_ANGLE_framebuffer_multisample" 
     "GL_CHROMIUM_bind_generates_resource" 
     "GL_EXT_texture_compression_dxt1" 
     "GL_ANGLE_robust_client_memory" 
     "GL_NV_pixel_buffer_object" 
     "GL_EXT_texture_format_BGRA8888" 
     "GL_ANGLE_program_cache_control" 
     "GL_EXT_color_buffer_float" 
     "GL_OES_packed_depth_stencil" 
     "GL_ANGLE_lossy_etc_decode" 
     "GL_EXT_unpack_subimage" 
     "GL_OES_mapbuffer" 
     "GL_EXT_debug_marker" 
     "GL_OES_standard_derivatives" 
     "GL_OES_EGL_image" 
     "GL_ANGLE_multiview" 
     "GL_NV_fence" 
     "GL_OES_texture_float_linear" 
     "GL_OES_depth32" 
     "GL_OES_texture_half_float_linear" 
     "GL_OES_surfaceless_context" 
     "GL_OES_texture_npot" 
     "GL_OES_EGL_image_external_essl3" 
     "GL_EXT_disjoint_timer_query" 
     "GL_EXT_sRGB" 

QPA OpenGL Detection Info 
  supportsDesktopGL: true 
  supportsAngleD3D11: true 
  isQtPreferAngle: true 

useBufferInvalidation (config option): false


Hardware Information

  GPU Acceleration: auto
  Memory: 24510 Mb
  Number of Cores: 4
  Swap Location: C:/Users/Franck P. Rabeson/AppData/Local/Temp

Current Settings

  Current Swap Location: C:/Users/Franck P. Rabeson/AppData/Local/Temp
  Current Swap Location writable: true
  Undo Enabled: true
  Undo Stack Limit: 30
  Use OpenGL: true
  Use OpenGL Texture Buffer: true
  Disable Vector Optimizations: false
  Disable AVX Optimizations: false
  Canvas State: OPENGL_SUCCESS
  Autosave Interval: 900
  Use Backup Files: true
  Number of Backups Kept: 5
  Backup File Suffix: .bak
  Backup Location: Same Folder as the File
  Backup Location writable: false
  Use Win8 Pointer Input: false
  Use RightMiddleTabletButton Workaround: false
  Levels of Detail Enabled: false
  Use Zip64: false


Display Information
Number of screens: 2
	Screen: 0
		Name: \\.\DISPLAY1
		Depth: 32
		Scale: 1
		Resolution in pixels: 1920x1080
		Manufacturer: 
		Model: 
		Refresh Rate: 60
	Screen: 1
		Name: \\.\DISPLAY2
		Depth: 32
		Scale: 1
		Resolution in pixels: 1680x1050
		Manufacturer: 
		Model: 
		Refresh Rate: 60


---------------------
================================================================================
SESSION: 16 Nov 2021 21:12:52 +0300. Executing C:\Program Files\Krita (x64)\bin\krita.exe

Krita Version: 5.1.0-prealpha (git 4807d9c), Qt version compiled: 5.12.11, loaded: 5.12.11. Process ID: 22012
-- -- -- -- -- -- -- --
16 Nov 2021 21:12:52 +0300: Style: fusion. Available styles: windowsvista, Windows, Fusion
16 Nov 2021 21:13:00 +0300: Database is up to date. Version: 0.0.13, created by Krita 5.1.0-prealpha, at Sun Nov 14 20:55:26 2021
16 Nov 2021 21:14:34 +0300: Non-store package - creating updater
16 Nov 2021 21:15:08 +0300: Created image "Test_[brackets]", 512 * 512 pixels, 100 dpi. Color model: 8-bit integer/channel RGB/Alpha (sRGB-elle-V2-srgbtrc.icc). Layers: 1
16 Nov 2021 21:15:28 +0300: Saving Document  as E:/Test_[brackets].kra (mime: application/x-krita). 512 * 512 pixels, 2 layers.  101 frames, 24 framerate. Export configuration: No configuration
16 Nov 2021 21:15:28 +0300: Converting from application/x-krita to application/x-krita. Location: E:/Test_[brackets].kra. Real location: E:/Test_[brackets].kra. Batchmode: 0. Configuration: none
16 Nov 2021 21:15:28 +0300: Completed saving E:/Test_[brackets].kra (mime: application/x-krita). Result: OK. Warning: . Size: 25822
16 Nov 2021 21:15:28 +0300: Saving Completed
16 Nov 2021 21:15:38 +0300: Saving Document E:/Test_[brackets].kra as E:/Test_[brackets].kra (mime: application/x-krita). 512 * 512 pixels, 2 layers.  101 frames, 24 framerate. Export configuration: No configuration
16 Nov 2021 21:15:38 +0300: Create a simple backup for E:/Test_[brackets].kra in the same location as the file.
16 Nov 2021 21:15:38 +0300: Converting from application/x-krita to application/x-krita. Location: E:/Test_[brackets].kra. Real location: E:/Test_[brackets].kra. Batchmode: 0. Configuration: none
16 Nov 2021 21:15:38 +0300: Completed saving E:/Test_[brackets].kra (mime: application/x-krita). Result: OK. Warning: . Size: 384279
16 Nov 2021 21:15:38 +0300: Saving Completed
16 Nov 2021 21:15:42 +0300: Saving Document E:/Test_[brackets].kra as E:/Test_[brackets].kra (mime: application/x-krita). 512 * 512 pixels, 2 layers.  101 frames, 24 framerate. Export configuration: No configuration
16 Nov 2021 21:15:42 +0300: Failed to create a numbered backup for E:/Test_[brackets].kra.
16 Nov 2021 21:15:44 +0300: Saving Document E:/Test_[brackets].kra as E:/Test_[brackets].kra (mime: application/x-krita). 512 * 512 pixels, 2 layers.  101 frames, 24 framerate. Export configuration: No configuration
16 Nov 2021 21:15:44 +0300: Failed to create a numbered backup for E:/Test_[brackets].kra.
Comment 5 Bug Janitor Service 2021-11-17 04:39:17 UTC
Thanks for your comment!

Automatically switching the status of this bug to REPORTED so that the KDE team
knows that the bug is ready to get confirmed.

In the future you may also do this yourself when providing needed information.
Comment 6 Halla Rempt 2022-09-15 08:01:27 UTC
Sorry for the late reply -- we're getting inundated with bug reports. I can confirm the bug. The second backup isn't made.

Krita Version: 5.2.0-prealpha (git bb59f0c), Qt version compiled: 5.12.12, loaded: 5.12.12. Process ID: 2092492
-- -- -- -- -- -- -- --
15 Sep 2022 09:59:23 +0200: Style: fusion. Available styles: Windows, Fusion
15 Sep 2022 09:59:23 +0200: Database is up to date. Version: 0.0.17, created by Krita 5.2.0-prealpha, at wo sep. 14 15:49:09 2022
15 Sep 2022 09:59:39 +0200: Created image "Unnamed", 2480 * 3508 pixels, 300 dpi. Color model: 8-bit integer/channel RGB/Alpha (sRGB-elle-V2-srgbtrc.icc). Layers: 2
15 Sep 2022 10:00:20 +0200: Saving Document  as /home/halla/bla/bla_[brackets].kra (mime: application/x-krita). 2480 * 3508 pixels, 3 layers.  101 frames, 24 framerate. Export configuration: No configuration
15 Sep 2022 10:00:20 +0200: Converting from application/x-krita to application/x-krita. Location: /home/halla/bla/bla_[brackets].kra. Real location: /home/halla/bla/bla_[brackets].kra. Batchmode: 0. Configuration: none
15 Sep 2022 10:00:21 +0200: Completed saving /home/halla/bla/bla_[brackets].kra (mime: application/x-krita). Result: OK. Warning: . Size: 288366
15 Sep 2022 10:00:21 +0200: Saving Completed
15 Sep 2022 10:00:34 +0200: Saving Document /home/halla/bla/bla_[brackets].kra as /home/halla/bla/bla_[brackets].kra (mime: application/x-krita). 2480 * 3508 pixels, 3 layers.  101 frames, 24 framerate. Export configuration: No configuration
15 Sep 2022 10:00:34 +0200: Create a simple backup for /home/halla/bla/bla_[brackets].kra in the same location as the file.
15 Sep 2022 10:00:34 +0200: Converting from application/x-krita to application/x-krita. Location: /home/halla/bla/bla_[brackets].kra. Real location: /home/halla/bla/bla_[brackets].kra. Batchmode: 0. Configuration: none
15 Sep 2022 10:00:35 +0200: Completed saving /home/halla/bla/bla_[brackets].kra (mime: application/x-krita). Result: OK. Warning: . Size: 328983
15 Sep 2022 10:00:35 +0200: Saving Completed
15 Sep 2022 10:00:37 +0200: Saving Document /home/halla/bla/bla_[brackets].kra as /home/halla/bla/bla_[brackets].kra (mime: application/x-krita). 2480 * 3508 pixels, 3 layers.  101 frames, 24 framerate. Export configuration: No configuration
15 Sep 2022 10:00:37 +0200: Failed to create a numbered backup for /home/halla/bla/bla_[brackets].kra.
^C
halla@thinkstations:~/bla$ ls -la
total 616
drwxrwxr-x  2 halla halla   4096 sep 15 10:00  .
drwxr-xr-x 46 halla halla   4096 sep 15 09:07  ..
-rw-rw-r--  1 halla halla 328983 sep 15 10:00 'bla_[brackets].kra'
-rw-rw-r--  1 halla halla 288366 sep 15 10:00 'bla_[brackets].kra.1~'
Comment 7 Halla Rempt 2022-09-15 09:30:58 UTC
Git commit f1a3f003bc9a15b9e95dbc7e05494bcf080ec30d by Halla Rempt.
Committed on 15/09/2022 at 09:30.
Pushed by rempt into branch 'master'.

Fix creating numbered backups for files with [ and ]

Replace [ and ] with wildcards so files containing them are found i
by QDir.
(cherry picked from commit f24d3a0fa08d473c26ab2adf0892772cfaac2a3b)

M  +10   -3    libs/global/KisBackup.cpp

https://invent.kde.org/graphics/krita/commit/f1a3f003bc9a15b9e95dbc7e05494bcf080ec30d
Comment 8 Halla Rempt 2022-09-15 09:31:06 UTC
Git commit 620abbd87ae207f8833af94440dc552352ebbec5 by Halla Rempt.
Committed on 15/09/2022 at 09:30.
Pushed by rempt into branch 'master'.

Fork KBackup to investigate why numbered backups with [] fail
(cherry picked from commit 7f92164d2f22f28ce511f33d38c0ec8fb88429c6)

M  +1    -0    libs/global/CMakeLists.txt
A  +99   -0    libs/global/KisBackup.cpp     [License: LGPL(v2.0)]
A  +29   -0    libs/global/KisBackup.h     [License: LGPL(v2.0)]
M  +0    -1    libs/resources/KisFolderStorage.cpp
M  +2    -2    libs/resources/KisResourceCacheDb.cpp
M  +3    -3    libs/ui/KisDocument.cpp

https://invent.kde.org/graphics/krita/commit/620abbd87ae207f8833af94440dc552352ebbec5
Comment 9 Halla Rempt 2022-09-15 09:31:20 UTC
Git commit 8d2d60d8af2e5410d5dd7c13477913c7597156d4 by Halla Rempt.
Committed on 15/09/2022 at 09:31.
Pushed by rempt into branch 'krita/5.1'.

Fork KBackup to investigate why numbered backups with [] fail
(cherry picked from commit 7f92164d2f22f28ce511f33d38c0ec8fb88429c6)

M  +1    -0    libs/global/CMakeLists.txt
A  +99   -0    libs/global/KisBackup.cpp     [License: LGPL(v2.0)]
A  +29   -0    libs/global/KisBackup.h     [License: LGPL(v2.0)]
M  +0    -1    libs/resources/KisFolderStorage.cpp
M  +2    -2    libs/resources/KisResourceCacheDb.cpp
M  +3    -3    libs/ui/KisDocument.cpp

https://invent.kde.org/graphics/krita/commit/8d2d60d8af2e5410d5dd7c13477913c7597156d4
Comment 10 Halla Rempt 2022-09-15 09:31:28 UTC
Git commit 58a0e707882969e22b450382a21c4c4344d9be6f by Halla Rempt.
Committed on 15/09/2022 at 09:31.
Pushed by rempt into branch 'krita/5.1'.

Fix creating numbered backups for files with [ and ]

Replace [ and ] with wildcards so files containing them are found i
by QDir.
(cherry picked from commit f24d3a0fa08d473c26ab2adf0892772cfaac2a3b)

M  +10   -3    libs/global/KisBackup.cpp

https://invent.kde.org/graphics/krita/commit/58a0e707882969e22b450382a21c4c4344d9be6f
Comment 11 Halla Rempt 2022-09-15 09:33:53 UTC
I'm moving this bug to kcoreaddons. The problem here is that if there's [ or ] in a filename, QDir doesn't find the files anymore. They either need to be escaped, or these characters need to be replaced by a wildcard. I choose the latter when I was investiging this bug using a fork of KBackup. I'm not sure which solution is right, so I'm leaving that to the KCoreAddons maintainers.