Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit 9e00d76

Browse files
committed
Merge pull request #315 from adobe/jeff/linux-fs-api-impl
Implement missing APIs on Linux
2 parents 3bb18e0 + f5b6ab1 commit 9e00d76

File tree

2 files changed

+70
-6
lines changed

2 files changed

+70
-6
lines changed

appshell/appshell_extensions_gtk.cpp

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
GtkWidget* _menuWidget;
3737

3838
int ConvertLinuxErrorCode(int errorCode, bool isReading = true);
39+
int ConvertGnomeErrorCode(GError* gerror, bool isReading = true);
3940

4041
extern bool isReallyClosing;
4142

@@ -366,16 +367,15 @@ int DeleteFileOrDirectory(ExtensionString filename)
366367
return NO_ERROR;
367368
}
368369

370+
371+
369372
void MoveFileOrDirectoryToTrash(ExtensionString filename, CefRefPtr<CefBrowser> browser, CefRefPtr<CefProcessMessage> response)
370373
{
371374
int error = NO_ERROR;
372375
GFile *file = g_file_new_for_path(filename.c_str());
373376
GError *gerror = NULL;
374377
if (!g_file_trash(file, NULL, &gerror)) {
375-
if (gerror->code == G_IO_ERROR_NOT_FOUND)
376-
error = ERR_NOT_FOUND;
377-
else
378-
error = ERR_UNKNOWN;
378+
error = ConvertGnomeErrorCode(gerror);
379379
g_error_free(gerror);
380380
}
381381
g_object_unref(file);
@@ -419,6 +419,51 @@ int ShowFolderInOSWindow(ExtensionString pathname)
419419
return NO_ERROR;
420420
}
421421

422+
423+
int ConvertGnomeErrorCode(GError* gerror, bool isReading)
424+
{
425+
if (gerror == NULL)
426+
return NO_ERROR;
427+
428+
if (gerror->domain == G_FILE_ERROR) {
429+
switch(gerror->code) {
430+
case G_FILE_ERROR_EXIST:
431+
return ERR_FILE_EXISTS;
432+
case G_FILE_ERROR_NOTDIR:
433+
return ERR_NOT_DIRECTORY;
434+
case G_FILE_ERROR_ISDIR:
435+
return ERR_NOT_FILE;
436+
case G_FILE_ERROR_NXIO:
437+
case G_FILE_ERROR_NOENT:
438+
return ERR_NOT_FOUND;
439+
case G_FILE_ERROR_NOSPC:
440+
return ERR_OUT_OF_SPACE;
441+
case G_FILE_ERROR_INVAL:
442+
return ERR_INVALID_PARAMS;
443+
case G_FILE_ERROR_ROFS:
444+
return ERR_CANT_WRITE;
445+
case G_FILE_ERROR_BADF:
446+
case G_FILE_ERROR_ACCES:
447+
case G_FILE_ERROR_PERM:
448+
case G_FILE_ERROR_IO:
449+
return isReading ? ERR_CANT_READ : ERR_CANT_WRITE;
450+
default:
451+
return ERR_UNKNOWN;
452+
}
453+
} else if (gerror->domain == G_IO_ERROR) {
454+
switch(gerror->code) {
455+
case G_IO_ERROR_NOT_FOUND:
456+
return ERR_NOT_FOUND;
457+
case G_IO_ERROR_NO_SPACE:
458+
return ERR_OUT_OF_SPACE;
459+
case G_IO_ERROR_INVALID_ARGUMENT:
460+
return ERR_INVALID_PARAMS;
461+
default:
462+
return ERR_UNKNOWN;
463+
}
464+
}
465+
}
466+
422467
int ConvertLinuxErrorCode(int errorCode, bool isReading)
423468
{
424469
// printf("LINUX ERROR! %d %s\n", errorCode, strerror(errorCode));
@@ -444,6 +489,19 @@ int ConvertLinuxErrorCode(int errorCode, bool isReading)
444489

445490
int32 CopyFile(ExtensionString src, ExtensionString dest)
446491
{
492+
int error = NO_ERROR;
493+
GFile *source = g_file_new_for_path(src.c_str());
494+
GFile *destination = g_file_new_for_path(dest.c_str());
495+
GError *gerror = NULL;
496+
497+
if (!g_file_copy(source, destination, (GFileCopyFlags)(G_FILE_COPY_OVERWRITE|G_FILE_COPY_NOFOLLOW_SYMLINKS|G_FILE_COPY_TARGET_DEFAULT_PERMS), NULL, NULL, NULL, &gerror)) {
498+
error = ConvertGnomeErrorCode(gerror);
499+
g_error_free(gerror);
500+
}
501+
g_object_unref(source);
502+
g_object_unref(destination);
503+
504+
return error;
447505
}
448506

449507
int32 GetPendingFilesToOpen(ExtensionString& files)

appshell/client_app_gtk.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
//#include <MMSystem.h>
3232
//#include <ShlObj.h>
3333
#include <string>
34+
#include <glib.h>
3435

3536
extern time_t g_appStartupTime;
3637
extern char _binary_appshell_appshell_extensions_js_start;
@@ -96,6 +97,11 @@ CefString ClientApp::AppGetSupportDirectory()
9697

9798
CefString ClientApp::AppGetDocumentsDirectory()
9899
{
99-
std::string home_dir(getenv("HOME"));
100-
return home_dir;
100+
const char *dir = g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS);
101+
if (dir == NULL) {
102+
return AppGetSupportDirectory();
103+
} else {
104+
std::string documents_dir (dir);
105+
return documents_dir;
106+
}
101107
}

0 commit comments

Comments
 (0)