Bug 417722 - Cannot Drag/Drop Screenshot Due To Subfolder in Filename
Summary: Cannot Drag/Drop Screenshot Due To Subfolder in Filename
Status: RESOLVED FIXED
Alias: None
Product: Spectacle
Classification: Applications
Component: General (show other bugs)
Version: 19.12.2
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Boudhayan Gupta
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-15 21:24 UTC by Dubfiance
Modified: 2020-04-13 01:34 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 20.04.0


Attachments
patch for creating subdirs in tmp dir (2.00 KB, patch)
2020-04-09 13:50 UTC, brainpower
Details
correct patch for creating subdirs in tmp dir (1.91 KB, patch)
2020-04-09 13:52 UTC, brainpower
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dubfiance 2020-02-15 21:24:22 UTC
SUMMARY
I had Spectacle to save my screenshots under folders that change every month and year. This has been working perfectly fine between the months of August to February where now the program does make these folders when I save or copy the image to the clipboard, but I get an error of "Cannot Save Screenshot. Error while writing temporary local file." when I try to drag and drop the image into applications I want to send it to.

STEPS TO REPRODUCE
1. Set the save location file name to have a subfolder. (i.e. "%Y-%M/Screenshot_%T_%Y%M%D_%H%m%S")
2. Close the program.
3. Take a screenshot.
4. Try to drag and drop the image.

OBSERVED RESULT
Error with "Cannot Save Screenshot. Error while writing temporary local file."

EXPECTED RESULT
To drag the image and drop it to any program without issue.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: KDE neon 5.18.0 (Kernel 5.3.0-28-generic)
(available in About System)
KDE Plasma Version: 5.18.0
KDE Frameworks Version: 5.67.0
Qt Version: 5.13.2

ADDITIONAL INFORMATION
Comment 1 brainpower 2020-02-29 15:58:54 UTC
I have the same Problem. I've also configured Subfolders based on date.
My save filename is set to to "%Y/%M/screen-%2d".


Ran spectacle in strace and saw it try to open a file in /tmp without mkdir-ing the subfolders first, thus failing.

  openat(AT_FDCWD, "/tmp/Spectacle.MIzolT/2020/02/screen-01.png", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = -1 ENOENT (No such file or directory)


The temporary dir exists, the subfolders do not:

  % tree /tmp/Spectacle.MIzolT
  /tmp/Spectacle.MIzolT

  0 directories, 0 files

After that I ran

  mkdir -p /tmp/Spectacle.MIzolT/2020/02/

and tried again, no error occurred then and the screenshot was saved correctly:

  % tree /tmp/Spectacle.MIzolT
  /tmp/Spectacle.MIzolT
  └── 2020
      └── 02
          └── screen-01.png

  2 directories, 1 file



So spectacle should do either of:
1. Create the subdirs if they do not exist, as it does when savong normally
2. Strip the subdirs when saving temporarily



VERSION INFORMATION

% spectacle --version
spectacle 19.12.2

Operating System: Arch Linux 
KDE Plasma Version: 5.18.2
KDE Frameworks Version: 5.67.0
Qt Version: 5.15.0
Kernel Version: 5.5.6-arch1-1
Comment 2 brainpower 2020-04-09 13:50:09 UTC
Created attachment 127406 [details]
patch for creating subdirs in tmp dir

I've been using this patch for a while now with 0.03.90 and 0.03.80.
Worked fine for me, but I'm not sure if that's the way to properly do it.
localSave() uses similar code, though.
Comment 3 brainpower 2020-04-09 13:52:40 UTC
Created attachment 127407 [details]
correct patch for creating subdirs in tmp dir

Sorry, wrong patch file, this is the correct one.
Comment 5 brainpower 2020-04-09 13:58:47 UTC
oh, I thought that was for dev's only not for "casual patch posting".
Sorry. Will try submitting to phabricator soon.
Comment 6 brainpower 2020-04-09 14:08:50 UTC
Did I do it right?
 https://phabricator.kde.org/D28702
Comment 7 Nate Graham 2020-04-09 14:15:39 UTC
You did! Let's continue there.
Comment 8 Nate Graham 2020-04-13 01:33:25 UTC
Git commit 464dde9677f4270c5d2ecfddf45c192a33493efe by Nate Graham, on behalf of Franz Baumgärtner.
Committed on 13/04/2020 at 01:33.
Pushed by ngraham into branch 'release/20.04'.

Fix inability to Drag+Drop screenshot due to subfolder in filename

Summary:
Fixes the mentioned bug by creating all necessary subdirectories.

Test Plan:
1. Set save Filename in Spectacle to one including one or more `/`, thus including subdirectories. Example: `%Y/%M/screen-%2d`
2. Take a screenshot
3. Start dragging the preview

Reviewers: #spectacle, davidre, ngraham

Reviewed By: #spectacle, davidre, ngraham

Subscribers: ngraham, davidre, #spectacle

Tags: #spectacle

Differential Revision: https://phabricator.kde.org/D28702

M  +2    -1    src/ExportManager.cpp

https://commits.kde.org/spectacle/464dde9677f4270c5d2ecfddf45c192a33493efe