diff options
author | Andrii Kroitor <an.kroitor@samsung.com> | 2016-12-09 15:38:54 +0200 |
---|---|---|
committer | Andrii Kroitor <an.kroitor@samsung.com> | 2016-12-09 16:54:12 +0200 |
commit | 62a0c41fd3bf8796efec55db52395f13a78fb27f (patch) | |
tree | 6727162656f543dc4d94de37ceb259e140b2d535 /src/lib/ethumb/ethumb.c | |
parent | 05ca887e41c17a5a5a1eb2d36d35df504e7bdcff (diff) |
ethumb: fix absolute path generation
replace _ethumb_build_absolute_path with eina_file_path_sanitize
It makes same thing and works on Windows correctly.
Diffstat (limited to 'src/lib/ethumb/ethumb.c')
-rw-r--r-- | src/lib/ethumb/ethumb.c | 84 |
1 files changed, 15 insertions, 69 deletions
diff --git a/src/lib/ethumb/ethumb.c b/src/lib/ethumb/ethumb.c index ab7eda629e..7b8f4f008a 100644 --- a/src/lib/ethumb/ethumb.c +++ b/src/lib/ethumb/ethumb.c | |||
@@ -690,73 +690,16 @@ ethumb_frame_get(const Ethumb *e, const char **theme_file, const char **group, c | |||
690 | } | 690 | } |
691 | } | 691 | } |
692 | 692 | ||
693 | static const char * | ||
694 | _ethumb_build_absolute_path(const char *path, char buf[PATH_MAX]) | ||
695 | { | ||
696 | char *p; | ||
697 | int len; | ||
698 | |||
699 | if (!path) | ||
700 | return NULL; | ||
701 | |||
702 | p = buf; | ||
703 | |||
704 | if (path[0] == '/') | ||
705 | { | ||
706 | strncpy(p, path, PATH_MAX - 1); | ||
707 | p[PATH_MAX - 1] = 0; | ||
708 | } | ||
709 | else if (path[0] == '~') | ||
710 | { | ||
711 | #if defined(HAVE_GETUID) && defined(HAVE_GETEUID) | ||
712 | if (getuid() == geteuid()) | ||
713 | #endif | ||
714 | { | ||
715 | const char *home = eina_environment_home_get(); | ||
716 | if (!home) return NULL; | ||
717 | strncpy(p, home, PATH_MAX - 1); | ||
718 | p[PATH_MAX - 1] = 0; | ||
719 | } | ||
720 | #if defined(HAVE_GETUID) && defined(HAVE_GETEUID) | ||
721 | else | ||
722 | { | ||
723 | struct passwd *pw = getpwent(); | ||
724 | |||
725 | if ((!pw) || (!pw->pw_dir)) return NULL; | ||
726 | strncpy(p, pw->pw_dir, PATH_MAX - 1); | ||
727 | p[PATH_MAX - 1] = 0; | ||
728 | } | ||
729 | #endif | ||
730 | len = strlen(p); | ||
731 | p += len; | ||
732 | p[0] = '/'; | ||
733 | p++; | ||
734 | strcpy(p, path + 2); | ||
735 | } | ||
736 | else | ||
737 | { | ||
738 | if (!getcwd(p, PATH_MAX)) | ||
739 | return NULL; | ||
740 | len = strlen(p); | ||
741 | p += len; | ||
742 | p[0] = '/'; | ||
743 | p++; | ||
744 | strncpy(p, path, PATH_MAX - 1 - len - 1); | ||
745 | p[PATH_MAX - 1 - len - 1] = 0; | ||
746 | } | ||
747 | |||
748 | return buf; | ||
749 | } | ||
750 | |||
751 | EAPI void | 693 | EAPI void |
752 | ethumb_thumb_dir_path_set(Ethumb *e, const char *path) | 694 | ethumb_thumb_dir_path_set(Ethumb *e, const char *path) |
753 | { | 695 | { |
754 | char buf[PATH_MAX]; | 696 | char *sanitized_path; |
755 | EINA_SAFETY_ON_NULL_RETURN(e); | 697 | EINA_SAFETY_ON_NULL_RETURN(e); |
756 | 698 | ||
757 | DBG("ethumb=%p, path=%s", e, path ? path : ""); | 699 | DBG("ethumb=%p, path=%s", e, path ? path : ""); |
758 | path = _ethumb_build_absolute_path(path, buf); | 700 | sanitized_path = eina_file_path_sanitize(path); |
759 | eina_stringshare_replace(&e->thumb_dir, path); | 701 | eina_stringshare_replace(&e->thumb_dir, sanitized_path); |
702 | free(sanitized_path); | ||
760 | } | 703 | } |
761 | 704 | ||
762 | EAPI const char * | 705 | EAPI const char * |
@@ -893,19 +836,20 @@ ethumb_document_page_get(const Ethumb *e) | |||
893 | EAPI Eina_Bool | 836 | EAPI Eina_Bool |
894 | ethumb_file_set(Ethumb *e, const char *path, const char *key) | 837 | ethumb_file_set(Ethumb *e, const char *path, const char *key) |
895 | { | 838 | { |
896 | char buf[PATH_MAX]; | 839 | char *sanitized_path; |
897 | EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0); | 840 | EINA_SAFETY_ON_NULL_RETURN_VAL(e, 0); |
898 | 841 | ||
899 | eina_stringshare_replace(&e->thumb_path, NULL); | 842 | eina_stringshare_replace(&e->thumb_path, NULL); |
900 | eina_stringshare_replace(&e->thumb_key, NULL); | 843 | eina_stringshare_replace(&e->thumb_key, NULL); |
901 | 844 | ||
902 | DBG("ethumb=%p, path=%s, key=%s", e, path ? path : "", key ? key : ""); | 845 | sanitized_path = eina_file_path_sanitize(path); |
903 | if (path && access(path, R_OK)) return EINA_FALSE; | 846 | DBG("ethumb=%p, path=%s, key=%s", e, sanitized_path ? sanitized_path : "", key ? key : ""); |
847 | if (sanitized_path && access(sanitized_path, R_OK)) return EINA_FALSE; | ||
904 | 848 | ||
905 | path = _ethumb_build_absolute_path(path, buf); | ||
906 | eina_stringshare_replace(&e->src_hash, NULL); | 849 | eina_stringshare_replace(&e->src_hash, NULL); |
907 | eina_stringshare_replace(&e->src_path, path); | 850 | eina_stringshare_replace(&e->src_path, sanitized_path); |
908 | eina_stringshare_replace(&e->src_key, key); | 851 | eina_stringshare_replace(&e->src_key, key); |
852 | free(sanitized_path); | ||
909 | 853 | ||
910 | return EINA_TRUE; | 854 | return EINA_TRUE; |
911 | } | 855 | } |
@@ -1141,7 +1085,7 @@ ethumb_file_free(Ethumb *e) | |||
1141 | EAPI void | 1085 | EAPI void |
1142 | ethumb_thumb_path_set(Ethumb *e, const char *path, const char *key) | 1086 | ethumb_thumb_path_set(Ethumb *e, const char *path, const char *key) |
1143 | { | 1087 | { |
1144 | char buf[PATH_MAX]; | 1088 | char *sanitized_path; |
1145 | 1089 | ||
1146 | EINA_SAFETY_ON_NULL_RETURN(e); | 1090 | EINA_SAFETY_ON_NULL_RETURN(e); |
1147 | DBG("ethumb=%p, path=%s, key=%s", e, path ? path : "", key ? key : ""); | 1091 | DBG("ethumb=%p, path=%s, key=%s", e, path ? path : "", key ? key : ""); |
@@ -1153,9 +1097,11 @@ ethumb_thumb_path_set(Ethumb *e, const char *path, const char *key) | |||
1153 | } | 1097 | } |
1154 | else | 1098 | else |
1155 | { | 1099 | { |
1156 | path = _ethumb_build_absolute_path(path, buf); | 1100 | sanitized_path = eina_file_path_sanitize(path); |
1157 | eina_stringshare_replace(&e->thumb_path, path); | 1101 | path = eina_file_path_sanitize(path); |
1102 | eina_stringshare_replace(&e->thumb_path, sanitized_path); | ||
1158 | eina_stringshare_replace(&e->thumb_key, key); | 1103 | eina_stringshare_replace(&e->thumb_key, key); |
1104 | free(sanitized_path); | ||
1159 | } | 1105 | } |
1160 | } | 1106 | } |
1161 | 1107 | ||