added support for recursive copy in skel folder
authorImran Zaman <imran.zaman@intel.com>
Thu, 24 Oct 2013 09:52:01 +0000 (12:52 +0300)
committerImran Zaman <imran.zaman@intel.com>
Thu, 24 Oct 2013 09:52:01 +0000 (12:52 +0300)
src/common/gum-file.c
test/common/commontest.c
test/daemon/daemon-test.c
test/data/skel/examples.desktop
test/data/skel/recur/examples.desktop [new file with mode: 0644]

index c1d23c6..634c9dd 100644 (file)
@@ -403,15 +403,19 @@ gum_file_getsgnam (
 {
     struct sgrp *sgent = NULL;
     FILE *fp = NULL;
+    const gchar *shadow_file = NULL;
 
     if (!grpname || !config) {
         return NULL;
     }
 
-    if (!(fp = _open_file (gum_config_get_string (config,
-            GUM_CONFIG_GENERAL_GSHADOW_FILE), "r"))) {
+    shadow_file = gum_config_get_string (config,
+            GUM_CONFIG_GENERAL_GSHADOW_FILE);
+    if (!g_file_test (shadow_file, G_FILE_TEST_EXISTS) ||
+        !(fp = _open_file (shadow_file, "r"))) {
         return NULL;
     }
+
     while ((sgent = fgetsgent (fp)) != NULL) {
         if(g_strcmp0 (grpname, sgent->sg_namp) == 0)
             break;
@@ -443,6 +447,85 @@ gum_file_new_path (
        return file;
 }
 
+static gboolean
+_copy_dir_recursively (
+        GumConfig *config,
+        const gchar *src,
+        const gchar *dest,
+        uid_t uid,
+        gid_t gid,
+        GError **error)
+{
+    gboolean retval = TRUE;
+    gboolean stop = FALSE;
+    const gchar *src_fname = NULL;
+    gchar *src_filepath = NULL, *dest_filepath = NULL;
+    GDir *src_dir = NULL;
+    struct stat stat_entry;
+
+    if (!src || !dest) {
+        RETURN_WITH_ERROR (GUM_ERROR_HOME_DIR_COPY_FAILURE,
+                "Invalid directory path(s)", error, FALSE);
+    }
+
+    DBG ("copy directory %s -> %s", src, dest);
+    src_dir = g_dir_open (src, 0, NULL);
+    if (!src_dir) {
+        RETURN_WITH_ERROR (GUM_ERROR_HOME_DIR_COPY_FAILURE,
+                "Invalid source directory path", error, FALSE);
+    }
+
+    while ((src_fname = g_dir_read_name (src_dir))) {
+        GError *err = NULL;
+        GFile *src_file = NULL, *dest_file = NULL;
+
+        src_filepath = g_build_filename (src, src_fname, NULL);
+        stop = (lstat(src_filepath, &stat_entry) != 0);
+        if (stop) goto _free_data;
+
+        dest_filepath = g_build_filename (dest, src_fname, NULL);
+        src_file = g_file_new_for_path (src_filepath);
+        dest_file = g_file_new_for_path (dest_filepath);
+
+        if (S_ISDIR (stat_entry.st_mode)) {
+            DBG ("copy directory %s", src_filepath);
+            gint mode = GUM_PERM & ~gum_config_get_uint (config,
+                        GUM_CONFIG_GENERAL_UMASK, GUM_UMASK);
+            g_mkdir_with_parents (dest_filepath, mode);
+            stop = !_copy_dir_recursively (config, src_filepath, dest_filepath,
+                    uid, gid, NULL);
+        } else {
+            DBG ("copy file %s", src_filepath);
+            if (!g_file_copy (src_file, dest_file,
+                    G_FILE_COPY_OVERWRITE | G_FILE_COPY_NOFOLLOW_SYMLINKS, NULL,
+                    NULL, NULL, &err)) {
+                WARN("File copy failure error %d:%s", err ? err->code : 0,
+                        err ? err->message : "");
+                if (err) g_error_free (err);
+                stop = TRUE;
+                goto _free_data;
+            }
+#ifndef ENABLE_TESTS
+            stop = (chown (dest_filepath, uid, gid) < 0);
+#endif
+        }
+
+_free_data:
+        g_free (src_filepath);
+        g_free (dest_filepath);
+        GUM_OBJECT_UNREF (src_file);
+        GUM_OBJECT_UNREF (dest_file);
+        if (stop) {
+            SET_ERROR (GUM_ERROR_HOME_DIR_COPY_FAILURE,
+                    "Home directory copy failure", error, retval, FALSE);
+            break;
+        }
+    }
+
+    g_dir_close (src_dir);
+    return retval;
+}
+
 gboolean
 gum_file_create_home_dir (
         GumConfig *config,
@@ -462,8 +545,6 @@ gum_file_create_home_dir (
 
     if (g_access (usr_home_dir, F_OK) != 0) {
 
-        GDir* skel_dir = NULL;
-        const gchar *skel_dir_path = NULL;
         if (!g_file_test (usr_home_dir, G_FILE_TEST_EXISTS)) {
             g_mkdir_with_parents (usr_home_dir, mode);
         }
@@ -480,43 +561,10 @@ gum_file_create_home_dir (
                                        "Home directory chown failure", error, FALSE);
                }
 #endif
-               skel_dir_path = gum_config_get_string (config,
-                               GUM_CONFIG_GENERAL_SKEL_DIR);
-               skel_dir = g_dir_open(skel_dir_path, 0, NULL);
-               if (skel_dir) {
-                       gchar *dpath = NULL;
-                       const gchar *fname = NULL;
-                       GFile *src = NULL, *dest = NULL;
-                       while ((fname = g_dir_read_name(skel_dir)) != NULL) {
-                               GError *err = NULL;
-                               src = gum_file_new_path (skel_dir_path, fname);
-                               dest = gum_file_new_path (usr_home_dir, fname);
-                               dpath = g_file_get_path (dest);
-                               if (!src ||
-                                       !dest ||
-                                       !g_file_copy (src, dest, G_FILE_COPY_OVERWRITE, NULL, NULL,
-                                                       NULL, &err)
-#ifndef ENABLE_TESTS
-                                   || (chown (dpath, uid, gid) < 0)
-#endif
-                                   ) {
-                                       WARN("File copy failure error %d:%s", err ? err->code : 0,
-                                                       err ? err->message : "");
-                                       if (err) g_error_free (err);
-                       GUM_OBJECT_UNREF (src);
-                       GUM_OBJECT_UNREF (dest);
-                                       g_free (dpath);
-                                       SET_ERROR (GUM_ERROR_HOME_DIR_COPY_FAILURE,
-                                                       "Home directory copy failure", error, retval,
-                                                       FALSE);
-                                       break;
-                               }
-                               GUM_OBJECT_UNREF (src);
-                GUM_OBJECT_UNREF (dest);
-                               g_free (dpath);
-                       }
-                       g_dir_close(skel_dir);
-               }
+
+               retval = _copy_dir_recursively (config, gum_config_get_string (config,
+                GUM_CONFIG_GENERAL_SKEL_DIR), usr_home_dir, uid, gid,
+                       error);
        }
 
        return retval;
index 2f04237..a5fbaba 100644 (file)
@@ -90,7 +90,7 @@ _setup (void)
     fail_if (system(cmd) != 0, "Failed to copy temp skel dir: %s\n",
             strerror(errno));
     g_free (cmd);
-    fail_if (system("chmod +w /tmp/gum/skel") != 0);
+    fail_if (system("chmod -R +w /tmp/gum/skel") != 0);
 
     fpath = g_build_filename (GUM_TEST_DATA_DIR, "passwd", NULL);
     fail_if (_create_file (g_getenv("UM_PASSWD_FILE"), fpath) == FALSE);
index a632767..0306a76 100644 (file)
@@ -118,7 +118,7 @@ _setup_env (void)
     fail_if (system(cmd) != 0, "Failed to copy temp skel dir: %s:%s\n", cmd,
             strerror(errno));
     g_free (cmd);
-    fail_if (system("chmod +w /tmp/gum/skel") != 0);
+    fail_if (system("chmod -R +w /tmp/gum/skel") != 0);
 
     fpath = g_build_filename (GUM_TEST_DATA_DIR, "passwd", NULL);
     fail_if (_create_file (g_getenv("UM_PASSWD_FILE"), fpath) == FALSE);
index 3ed1d76..34576f5 100644 (file)
@@ -1,227 +1,4 @@
 [Desktop Entry]
 Version=1.0
 Type=Link
-Name=Examples
-Name[aa]=Ceelallo
-Name[ace]=Contoh
-Name[af]=Voorbeelde
-Name[am]=ምሳሌዎች
-Name[an]=Exemplos
-Name[ar]=أمثلة
-Name[ast]=Exemplos
-Name[az]=Nümunələr
-Name[be]=Прыклады
-Name[bg]=Примери
-Name[bn]=উদাহরণ
-Name[br]=Skouerioù
-Name[bs]=Primjeri
-Name[ca]=Exemples
-Name[ca@valencia]=Exemples
-Name[ckb]=نمونه‌كان
-Name[cs]=Ukázky
-Name[csb]=Przëmiôrë
-Name[cy]=Enghreifftiau
-Name[da]=Eksempler
-Name[de]=Beispiele
-Name[dv]=މިސާލުތަށް
-Name[el]=Παραδείγματα
-Name[en_AU]=Examples
-Name[en_CA]=Examples
-Name[en_GB]=Examples
-Name[eo]=Ekzemploj
-Name[es]=Ejemplos
-Name[et]=Näidised
-Name[eu]=Adibideak
-Name[fi]=Esimerkkejä
-Name[fil]=Mga halimbawa
-Name[fo]=Dømir
-Name[fr]=Exemples
-Name[fur]=Esemplis
-Name[fy]=Foarbylden
-Name[ga]=Samplaí
-Name[gd]=Eisimpleirean
-Name[gl]=Exemplos
-Name[gu]=દૃષ્ટાન્તો
-Name[gv]=Sampleyryn
-Name[he]=דוגמאות
-Name[hi]=उदाहरण
-Name[hr]=Primjeri
-Name[ht]=Egzanp
-Name[hu]=Minták
-Name[hy]=Օրինակներ
-Name[id]=Contoh
-Name[is]=Sýnishorn
-Name[it]=Esempi
-Name[ja]=サンプル
-Name[ka]=ნიმუშები
-Name[kk]=Мысалдар
-Name[kl]=Assersuutit
-Name[km]=ឧទាហរណ៍
-Name[kn]=ಉದಾಹರಣೆಗಳು
-Name[ko]=예시
-Name[ku]=Mînak
-Name[lb]=Beispiller
-Name[lt]=Pavyzdžių failai
-Name[lv]=Paraugi
-Name[mg]=Ohatra
-Name[mhr]=Пример-влак
-Name[mi]=Tauira
-Name[mk]=Примери
-Name[ml]=ഉദാഹരണങ്ങള്‍
-Name[mr]=उदाहरणे
-Name[ms]=Contoh-contoh
-Name[my]=ဥပမာများ
-Name[nb]=Eksempler
-Name[nds]=Bispelen
-Name[ne]=उदाहरणहरू
-Name[nl]=Voorbeeldbestanden
-Name[nn]=Døme
-Name[nso]=Mehlala
-Name[oc]=Exemples
-Name[pa]=ਉਦਾਹਰਨਾਂ
-Name[pl]=Przykłady
-Name[pt]=Exemplos
-Name[pt_BR]=Exemplos
-Name[ro]=Exemple
-Name[ru]=Примеры
-Name[sc]=Esempiusu
-Name[sco]=Examples
-Name[sd]=مثالون
-Name[si]=උදාහරණ
-Name[sk]=Príklady
-Name[sl]=Zgledi
-Name[sml]=Saga Saupama
-Name[sn]=Miyenzaniso
-Name[sq]=Shembujt
-Name[sr]=Примери
-Name[sv]=Exempel
-Name[sw]=Mifano
-Name[ta]=உதாரணங்கள்
-Name[ta_LK]=உதாரணங்கள்
-Name[te]=ఉదాహరణలు
-Name[th]=ตัวอย่าง
-Name[tr]=Örnekler
-Name[tt]=Мисаллар
-Name[ug]=مىساللار
-Name[uk]=Приклади
-Name[ur]=مثالیں
-Name[uz]=Намуналар
-Name[vec]=Esempi
-Name[vi]=Mẫu ví dụ
-Name[wae]=Bischbil
-Name[zh_CN]=示例
-Name[zh_HK]=範例
-Name[zh_TW]=範例
-Comment=Example content for Ubuntu
-Comment[aa]=Ubuntuh addattinoh ceelallo
-Comment[ace]=Contoh aso ke Ubuntu
-Comment[af]=Voorbeeldmedia vir Ubuntu
-Comment[am]=ዝርዝር ምሳሌዎች ለ ኡቡንቱ
-Comment[an]=Conteniu d'exemplo ta Ubuntu
-Comment[ar]=أمثلة محتوى لأوبونتو
-Comment[ast]=Conteníu del exemplu pa Ubuntu
-Comment[az]=Ubuntu üçün nümunə material
-Comment[be]=Узоры дакументаў для Ubuntu
-Comment[bg]=Примерно съдържание за Ubuntu
-Comment[bn]=উবুন্টু সংক্রান্ত নমুনা তথ্য
-Comment[br]=Skouerenn endalc'had evit Ubuntu
-Comment[bs]=Primjer sadrzaja za Ubuntu
-Comment[ca]=Continguts d'exemple per a l'Ubuntu
-Comment[ca@valencia]=Continguts d'exemple per a l'Ubuntu
-Comment[ckb]=نموونەی ناوەڕۆکێک بۆ ئوبوونتو
-Comment[cs]=Ukázkový obsah pro Ubuntu
-Comment[csb]=Przëmiôrowô zamkłosc dlô Ubuntu
-Comment[cy]=Cynnwys enghraifft ar gyfer  Ubuntu
-Comment[da]=Eksempel indhold til Ubuntu
-Comment[de]=Beispielinhalt für Ubuntu
-Comment[dv]=އުބުންޓު އާއި އެކަށޭނަ މިސާލުތައް
-Comment[el]=Παραδείγματα περιεχομένου για το Ubuntu
-Comment[en_AU]=Example content for Ubuntu
-Comment[en_CA]=Example content for Ubuntu
-Comment[en_GB]=Example content for Ubuntu
-Comment[eo]=Ekzempla enhavo por Ubuntu
-Comment[es]=Contenido del ejemplo para Ubuntu
-Comment[et]=Ubuntu näidisfailid
-Comment[eu]=Adibidezko edukia Ubunturako
-Comment[fi]=Esimerkkisisältöjä Ubuntulle
-Comment[fil]=Halimbawang laman para sa Ubuntu
-Comment[fo]=Dømis innihald fyri Ubuntu
-Comment[fr]=Exemples de contenu pour Ubuntu
-Comment[fur]=Contignûts di esempli par Ubuntu
-Comment[fy]=Foarbyld fan ynhâld foar Ubuntu
-Comment[gd]=Eisimpleir susbaint airson Ubuntu
-Comment[gl]=Contido do exemplo para Ubuntu
-Comment[gu]=Ubuntu માટે ઉદાહરણ સૂચી
-Comment[gv]=Stoo Sanpleyr son Ubuntu
-Comment[he]=תוכן לדוגמה עבור אובונטו
-Comment[hi]=उबुन्टू हेतु उदाहरण सारांश
-Comment[hr]=Primjeri sadržaja za Ubuntu
-Comment[ht]=Kontni egzanplè pou Ubuntu
-Comment[hu]=Mintatartalom Ubuntuhoz
-Comment[hy]=Բովանդակության օրինակները Ubuntu֊ի համար
-Comment[id]=Contoh isi bagi Ubuntu
-Comment[is]=Sýnishorn fyrir Ubuntu
-Comment[it]=Contenuti di esempio per Ubuntu
-Comment[ja]=Ubuntuのサンプルコンテンツ
-Comment[ka]=უბუნტუს სანიმუშო შიგთავსი
-Comment[kk]=Ubuntu құжаттар мысалдары
-Comment[kl]=Ubuntu-mut imarisaanut assersuut
-Comment[km]=ឧទាហរណ៍សម្រាប់អាប់ប៊ុនធូ
-Comment[kn]=ಉಬುಂಟುಗೆ ಉದಾಹರಣೆಗಳು
-Comment[ko]=우분투 컨텐츠 예시
-Comment[ku]=Ji bo Ubuntu mînaka naverokê
-Comment[lb]=Beispillinhalt fir Ubuntu
-Comment[lt]=Įvairių dokumentų, paveikslėlių, garsų bei vaizdų pavyzdžiai
-Comment[lv]=Parauga saturs Ubuntu videi
-Comment[mg]=Ohatra ho an'i Ubuntu
-Comment[mhr]=Ubuntu-лан документ-влакын пример-влак
-Comment[mi]=Mata tauira o Ubuntu
-Comment[mk]=Пример содржина за Убунту
-Comment[ml]=ഉബുണ്ടുവിനു വേണ്ടിയുള്ള ഉദാഹരണങ്ങള്‍
-Comment[mr]=उबंटूसाठी घटकांची उदाहरणे
-Comment[ms]=Kandungan contoh untuk Ubuntu
-Comment[my]=Ubuntu အတွက် နမူနာ မာတိကာ
-Comment[nb]=Eksempelinnhold for Ubuntu
-Comment[ne]=उबन्टुका लागि उदाहरण सामग्री
-Comment[nl]=Voorbeeldinhoud voor Ubuntu
-Comment[nn]=Eksempelinnhald for Ubuntu
-Comment[nso]=Mohlala wa dikagare tša Ubuntu
-Comment[oc]=Exemples de contengut per Ubuntu
-Comment[pa]=ਉਬਤੂੰ ਲਈ ਨਮੂਨਾ ਸਮੱਗਰੀ
-Comment[pl]=Przykładowa zawartość dla Ubuntu
-Comment[pt]=Conteúdo de exemplo para o Ubuntu
-Comment[pt_BR]=Exemplo de conteúdo para Ubuntu
-Comment[ro]=Conținut exemplu pentru Ubuntu
-Comment[ru]=Примеры документов для Ubuntu
-Comment[sc]=Esempiu de cabidu pro Ubuntu
-Comment[sco]=Example content fur Ubuntu
-Comment[sd]=اوبنٽو لاءِ مثال طور ڏنل مواد
-Comment[si]=උබුන්ටු සඳහා උදාහරණ අන්තර්ගතයන්
-Comment[sk]=Ukážkový obsah pre Ubuntu
-Comment[sl]=Ponazoritvena vsebina za Ubuntu
-Comment[sml]=Saupama Isina Ubuntu
-Comment[sn]=Muyenzaniso wehuiswa kuitira Ubuntu
-Comment[sq]=Shembull i përmbajtjes për Ubuntu
-Comment[sr]=Садржај примера за Убунту
-Comment[sv]=Exempelinnehåll för Ubuntu
-Comment[sw]=Bidhaa mfano ya Ubuntu
-Comment[ta]=உபுண்டுவிற்கான எடுத்துகாட்டு உள்ளடக்கங்கள்
-Comment[ta_LK]=உபுண்டுவிற்கான எடுத்துகாட்டு உள்ளடக்கங்கள்
-Comment[te]=ఉబుంటు వాడుక విధాన నమూనాలు
-Comment[th]=ตัวอย่างข้อมูลสำหรับ Ubuntu
-Comment[tr]=Ubuntu için örnek içerik
-Comment[tt]=Ubuntu өчен документ мисаллары
-Comment[ug]=ئۇبۇنتۇنىڭ مىساللىرى
-Comment[uk]=Приклади контенту для Ubuntu
-Comment[ur]=یوبنٹو کیلئے مثالی مواد
-Comment[uz]=Ubuntu учун намуна таркиби
-Comment[vec]=Contenuti de esempio de Ubuntu
-Comment[vi]=Mẫu ví dụ cho Ubuntu
-Comment[wae]=D'Ubuntu bischbildatijä
-Comment[zh_CN]=Ubuntu 示例内容
-Comment[zh_HK]=Ubuntu 的範例內容
-Comment[zh_TW]=Ubuntu 的範例內容
-URL=file:///usr/share/example-content/
-Icon=folder
-X-Ubuntu-Gettext-Domain=example-content
-
+Name=Examples
\ No newline at end of file
diff --git a/test/data/skel/recur/examples.desktop b/test/data/skel/recur/examples.desktop
new file mode 100644 (file)
index 0000000..34576f5
--- /dev/null
@@ -0,0 +1,4 @@
+[Desktop Entry]
+Version=1.0
+Type=Link
+Name=Examples
\ No newline at end of file