d2phap/ImageGlass · error · IOException
IGE: Could not move the file to trash: {filePath}
Error message
IGE: Could not move the file to trash: {filePath} What it means
Thrown by LinuxShellProvider.DeleteFile when moveToRecycleBin is true and FreeDesktopTrash.Trash returns false. On Linux the host implements the FreeDesktop trash spec directly (home trash at $HOME/.local/share/Trash) rather than relying on a portal or gio. A false return means the file could not be moved/copied into the home trash — for any of the documented failure modes in FreeDesktopTrash.cs.
Source
Thrown at source/ImageGlass.Linux/Common/ServiceProviders/LinuxShellProvider.cs:75
// Linux does not support foreground shell integration
return false;
}
/// <summary>
/// <inheritdoc/>
/// </summary>
public void DeleteFile(string filePath, bool moveToRecycleBin = true)
{
if (moveToRecycleBin)
{
// Move to the user's real trash via the FreeDesktop spec. We don't use
// the Trash portal (broken on some desktops) or 'gio trash' (targets
// the sandbox trash inside Flatpak). Throw on failure so the caller
// surfaces an error instead of silently "losing" the file.
if (!FreeDesktopTrash.Trash(filePath))
{
throw new IOException($"IGE: Could not move the file to trash: {filePath}");
}
}
else
{
File.Delete(filePath);
}
}
/// <summary>
/// <inheritdoc/>
/// </summary>
public object? GetForegroundWindowView()
{
// Linux does not have a foreground shell object
return null;
}
View on GitHub (pinned to 4a3c4fecef)
Solutions
- Verify the file still exists at the moment of the call and that $HOME is set in the environment.
- Check permissions on the source file and on ~/.local/share/Trash (must be writable by the user); inside Flatpak, ensure the home filesystem is granted.
- If the file is on a different filesystem and the copy+delete fallback ran out of space, free space or move within the same filesystem.
- Fall back to a permanent delete (DeleteFile with moveToRecycleBin=false) only if the user accepts data loss; otherwise surface the IO error.
Example fix
// before
if (!FreeDesktopTrash.Trash(filePath))
throw new IOException($"IGE: Could not move the file to trash: {filePath}");
// after — capture the specific reason Trash returned false so the user can act
var reason = FreeDesktopTrash.Trash(filePath, out var trashError);
if (!reason)
throw new IOException($"IGE: Could not move the file to trash: {filePath} ({trashError})"); Defensive patterns
Strategy: validation
Validate before calling
// Before trashing, confirm the file exists and HOME is usable on Linux.
if (!File.Exists(filePath) && !Directory.Exists(filePath)) throw new FileNotFoundException(filePath);
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HOME"))) throw new InvalidOperationException("HOME unset");
var trashRoot = Path.Combine(Environment.GetEnvironmentVariable("HOME")!, ".local", "share", "Trash");
Directory.CreateDirectory(Path.Combine(trashRoot, "files"));
Directory.CreateDirectory(Path.Combine(trashRoot, "info")); Type guard
static bool CanTrash(string filePath) =>
(File.Exists(filePath) || Directory.Exists(filePath))
&& !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HOME")); Try / catch
try { shellProvider.DeleteFile(filePath, moveToRecycleBin: true); }
catch (IOException ex) when (ex.Message.Contains("Could not move the file to trash"))
{ _log.Error($"Trash failed for {filePath}: {ex.Message}"); /* surface to user; do not auto-delete permanently */ } Prevention
- Confirm the file still exists at call time (race with file watchers is the most common cause).
- Ensure $HOME is set and ~/.local/share/Trash is writable in the runtime (sandbox/Flatpak must grant it).
- On cross-filesystem sources, ensure space for the copy+delete fallback.
- Inside Flatpak, verify the home trash dir is reachable, not the sandbox-private one.
- Never fall back to permanent delete automatically — surface the error and let the user decide.
When it happens
Trigger: Produced at LinuxShellProvider.cs:75 when FreeDesktopTrash.Trash(filePath) returns false. Trash returns false when: the file does not exist, $HOME is unset/empty, the trash info file cannot be created after 10000 name collisions, or the final File.Move/File.Copy/File.Delete fails (permissions, read-only filesystem, cross-device copy failure).
Common situations: File already deleted by the time the call runs (race with file watcher); $HOME unset in a container/sandbox environment; file on a read-only mount; insufficient permissions on the source file or on ~/.local/share/Trash; Flatpak sandbox denies access to the home trash dir; path is on a filesystem that does not support the move and the copy-fallback also failed (out of space).
Related errors
- IGE: This feature is not supported on Linux.
- IGE: could not finalize '{destFilePath}'. {moveError}
- IGE: This feature is not supported on {BHelper.OS}.
- Cannot remove the default theme pack.
AI-assisted analysis of d2phap/ImageGlass@4a3c4fecef (2026-08-13).
Data as JSON: /api/errors/e9c898fc7f7c7cc3.
Report an issue: GitHub.