-rw-r--r-- | core/symlinker/main.cpp | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/core/symlinker/main.cpp b/core/symlinker/main.cpp index 73d5166..6a04980 100644 --- a/core/symlinker/main.cpp +++ b/core/symlinker/main.cpp | |||
@@ -6,56 +6,74 @@ | |||
6 | #include <qstringlist.h> | 6 | #include <qstringlist.h> |
7 | 7 | ||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <unistd.h> //symlink() | 9 | #include <unistd.h> //symlink() |
10 | #include <sys/stat.h> // mkdir() | 10 | #include <sys/stat.h> // mkdir() |
11 | 11 | ||
12 | #include <sys/vfs.h> | 12 | #include <sys/vfs.h> |
13 | #include <mntent.h> | 13 | #include <mntent.h> |
14 | #include <errno.h> | ||
14 | 15 | ||
15 | static const char *listDir = "/usr/lib/ipkg/externinfo/"; | 16 | static const char *listDir = "/usr/lib/ipkg/externinfo/"; |
16 | 17 | ||
17 | static void createSymlinks( const QString &location, const QString &package ) | 18 | static void createSymlinks( const QString &location, const QString &package ) |
18 | { | 19 | { |
20 | |||
19 | QFile inFile( location + "/usr/lib/ipkg/info/" + package + ".list" ); | 21 | QFile inFile( location + "/usr/lib/ipkg/info/" + package + ".list" ); |
20 | mkdir( "/usr/lib/ipkg", 0777 ); | 22 | mkdir( "/usr/lib/ipkg", 0777 ); |
21 | mkdir( listDir, 0777 ); | 23 | mkdir( listDir, 0777 ); |
22 | 24 | ||
23 | QFile outFile( listDir + package + ".list"); | 25 | QFile outFile( listDir + package + ".list"); |
24 | 26 | ||
25 | //qDebug( "createSymlinks %s -> %s", inFile.name().ascii(), outFile.name().ascii() ); | 27 | // qDebug( "createSymlinks %s -> %s", inFile.name().ascii(), outFile.name().ascii() ); |
26 | 28 | ||
27 | 29 | ||
28 | 30 | ||
29 | if ( inFile.open(IO_ReadOnly) && outFile.open(IO_WriteOnly)) { | 31 | if ( inFile.open(IO_ReadOnly) && outFile.open(IO_WriteOnly)) { |
30 | QTextStream in(&inFile); | 32 | QTextStream in(&inFile); |
31 | QTextStream out(&outFile); | 33 | QTextStream out(&outFile); |
32 | 34 | ||
33 | QString s; | 35 | QString s; |
34 | while ( !in.eof() ) { // until end of file... | 36 | while ( !in.eof() ) { // until end of file... |
35 | s = in.readLine(); // line of text excluding '\n' | 37 | s = in.readLine(); // line of text excluding '\n' |
36 | //qDebug( "Read: %s", s.ascii() ); | 38 | // qDebug( "Read: %s", s.ascii() ); |
39 | if (s.find(location,0,true) >= 0){ | ||
40 | // qDebug( "Found!" ); | ||
41 | s = s.replace(location,""); | ||
42 | } | ||
43 | // qDebug( "Read after: %s", s.ascii() ); | ||
44 | |||
37 | // for s, do link/mkdir. | 45 | // for s, do link/mkdir. |
38 | if ( s.right(1) == "/" ) { | 46 | if ( s.right(1) == "/" ) { |
39 | //qDebug("do mkdir for %s", s.ascii()); | 47 | // qDebug("do mkdir for %s", s.ascii()); |
40 | mkdir( s.ascii(), 0777 ); | 48 | mkdir( s.ascii(), 0777 ); |
41 | //possible optimization: symlink directories | 49 | //possible optimization: symlink directories |
42 | //that don't exist already. -- Risky. | 50 | //that don't exist already. -- Risky. |
43 | } else { | 51 | } else { |
44 | //qDebug("do symlink for %s", s.ascii()); | 52 | // qDebug("do symlink for %s", s.ascii()); |
45 | QFileInfo ffi( s ); | 53 | QFileInfo ffi( s ); |
46 | //Don't try to symlink if a regular file exists already | 54 | //Don't try to symlink if a regular file exists already |
47 | if ( !ffi.exists() || ffi.isSymLink() ) { | 55 | if ( !ffi.exists() || ffi.isSymLink() ) { |
48 | symlink( (location+s).ascii(), s.ascii() ); | 56 | if (symlink( (location+s).ascii(), s.ascii() ) != 0){ |
57 | if (errno == ENOENT){ | ||
58 | // perror("Symlink Failed! "); | ||
59 | QString e=s.ascii(); | ||
60 | e = e.replace(ffi.fileName(),""); | ||
61 | // qDebug("DirName : %s",e.ascii() ); | ||
62 | system ( QString("mkdir -p ")+e.ascii() ); | ||
63 | if (symlink( (location+s).ascii(), s.ascii() ) != 0) | ||
64 | qDebug ("Big problem creating symlink and directory"); | ||
65 | } | ||
66 | } | ||
49 | // qDebug ( "Created %s" ,s.ascii() ); | 67 | // qDebug ( "Created %s" ,s.ascii() ); |
50 | out << s << "\n"; | 68 | out << s << "\n"; |
51 | } //else { | 69 | } else { |
52 | // qDebug( "%s exists already, not symlinked", s.ascii() ); | 70 | qDebug( "%s exists already, not symlinked", s.ascii() ); |
53 | // } | 71 | } |
54 | } | 72 | } |
55 | } | 73 | } |
56 | inFile.close(); | 74 | inFile.close(); |
57 | outFile.close(); | 75 | outFile.close(); |
58 | } | 76 | } |
59 | } | 77 | } |
60 | 78 | ||
61 | 79 | ||
@@ -65,24 +83,25 @@ static void removeSymlinks( const QString &package ) | |||
65 | QFile inFile( listDir + package + ".list" ); | 83 | QFile inFile( listDir + package + ".list" ); |
66 | 84 | ||
67 | if ( inFile.open(IO_ReadOnly) ) { | 85 | if ( inFile.open(IO_ReadOnly) ) { |
68 | QTextStream in(&inFile); | 86 | QTextStream in(&inFile); |
69 | 87 | ||
70 | QString s; | 88 | QString s; |
71 | while ( !in.eof() ) { // until end of file... | 89 | while ( !in.eof() ) { // until end of file... |
72 | s = in.readLine(); // line of text excluding '\n' | 90 | s = in.readLine(); // line of text excluding '\n' |
73 | //qDebug("remove symlink %s", s.ascii()); | 91 | // qDebug("remove symlink %s", s.ascii()); |
74 | QFileInfo ffi( s ); | 92 | QFileInfo ffi( s ); |
75 | //Confirm that it's still a symlink. | 93 | //Confirm that it's still a symlink. |
76 | if ( ffi.isSymLink() ) | 94 | if ( ffi.isSymLink() ){ |
77 | unlink( s.ascii() ); | 95 | unlink( s.ascii() ); |
78 | // qDebug ( "Removed %s", s.ascii() ); | 96 | // qDebug ( "Removed %s", s.ascii() );} |
79 | // else | 97 | // else |
80 | // qDebug( "Not removed %s", s.ascii() ); | 98 | // qDebug( "Not removed %s", s.ascii() ); |
99 | } | ||
81 | } | 100 | } |
82 | inFile.close(); | 101 | inFile.close(); |
83 | inFile.remove(); | 102 | inFile.remove(); |
84 | } | 103 | } |
85 | } | 104 | } |
86 | 105 | ||
87 | 106 | ||
88 | 107 | ||
@@ -107,25 +126,25 @@ static void updateSymlinks() | |||
107 | if ( mntfp ) { | 126 | if ( mntfp ) { |
108 | while ( (me = getmntent( mntfp )) != 0 ) { | 127 | while ( (me = getmntent( mntfp )) != 0 ) { |
109 | QString root = me->mnt_dir; | 128 | QString root = me->mnt_dir; |
110 | if ( root == "/" ) | 129 | if ( root == "/" ) |
111 | continue; | 130 | continue; |
112 | 131 | ||
113 | QString info = root + "/usr/lib/ipkg/info"; | 132 | QString info = root + "/usr/lib/ipkg/info"; |
114 | QDir infoDir( info ); | 133 | QDir infoDir( info ); |
115 | //qDebug( "looking at %s", info.ascii() ); | 134 | // qDebug( "looking at %s", info.ascii() ); |
116 | if ( infoDir.isReadable() ) { | 135 | if ( infoDir.isReadable() ) { |
117 | const QFileInfoList *packages = infoDir.entryInfoList( "*.list" ); // No tr | 136 | const QFileInfoList *packages = infoDir.entryInfoList( "*.list" ); // No tr |
118 | QFileInfoListIterator it( *packages ); | 137 | QFileInfoListIterator it( *packages ); |
119 | QFileInfo *fi; | 138 | QFileInfo *fi; |
120 | while (( fi = *it )) { | 139 | while (( fi = *it )) { |
121 | ++it; | 140 | ++it; |
122 | if ( knownPackages.contains( fi->fileName() ) ) { | 141 | if ( knownPackages.contains( fi->fileName() ) ) { |
123 | //qDebug( "found %s and we've seen it before", fi->fileName().latin1() ); | 142 | // qDebug( "found %s and we've seen it before", fi->fileName().latin1() ); |
124 | knownPackages.remove( fi->fileName() ); | 143 | knownPackages.remove( fi->fileName() ); |
125 | } else { | 144 | } else { |
126 | //it's a new one | 145 | //it's a new one |
127 | createSymlinks( root, fi->baseName() ); | 146 | createSymlinks( root, fi->baseName() ); |
128 | } | 147 | } |
129 | 148 | ||
130 | } | 149 | } |
131 | 150 | ||