View | Details | Raw Unified | Return to bug 190105 | Differences between
and this patch

Collapse All | Expand All

(-)luafilesystem/Makefile (-10 / +8 lines)
Lines 2-9 Link Here
2
# $FreeBSD: head/devel/luafilesystem/Makefile 345404 2014-02-21 13:36:12Z ehaupt $
2
# $FreeBSD: head/devel/luafilesystem/Makefile 345404 2014-02-21 13:36:12Z ehaupt $
3
3
4
PORTNAME=	luafilesystem
4
PORTNAME=	luafilesystem
5
PORTVERSION=	1.5.0
5
PORTVERSION=	1.6.2
6
CATEGORIES=	devel
6
CATEGORIES=	devel
7
DISTVERSION=	1.5.0
7
MASTER_SITES=	GH
8
MASTER_SITES=	GH
8
PKGNAMEPREFIX=	${LUA_PKGNAMEPREFIX}
9
PKGNAMEPREFIX=	${LUA_PKGNAMEPREFIX}
9
10
Lines 12-23 Link Here
12
13
13
LICENSE=	MIT
14
LICENSE=	MIT
14
15
15
USE_LUA=	5.1
16
USES=		lua:51+
16
17
17
USE_GITHUB=	yes
18
USE_GITHUB=	yes
18
GH_ACCOUNT=	keplerproject
19
GH_ACCOUNT=	keplerproject
19
GH_PROGECT=	${PORTNAME}
20
GH_PROGECT=	${PORTNAME}
20
GH_TAGNAME=	v${PORTVERSION}
21
GH_TAGNAME=	v1.5.0
21
GH_COMMIT=	8ff2013
22
GH_COMMIT=	8ff2013
22
23
23
ALL_TARGET=	lib
24
ALL_TARGET=	lib
Lines 25-34 Link Here
25
PLIST_FILES=	%%LUA_MODLIBDIR%%/lfs.so
26
PLIST_FILES=	%%LUA_MODLIBDIR%%/lfs.so
26
PORTDOCS=	*
27
PORTDOCS=	*
27
28
28
MAKE_ARGS+=	INCS="-I${LOCALBASE}/include/${LUA_SUBDIR}"
29
30
NO_STAGE=	yes
31
32
OPTIONS_DEFINE=	DOCS
29
OPTIONS_DEFINE=	DOCS
33
30
34
.include <bsd.port.options.mk>
31
.include <bsd.port.options.mk>
Lines 36-48 Link Here
36
post-patch:
33
post-patch:
37
	${REINPLACE_CMD} -e \
34
	${REINPLACE_CMD} -e \
38
		"s|%%PREFIX%%|${PREFIX}| ; \
35
		"s|%%PREFIX%%|${PREFIX}| ; \
39
		s|%%MODLIBDIR%%|${LUA_MODLIBDIR}| ; \
36
		s|%%MODLIBDIR%%|${STAGEDIR}${LUA_MODLIBDIR}| ; \
40
		s|%%INCDIR%%|${LUA_INCDIR}|" ${WRKSRC}/config
37
		s|%%INCDIR%%|${LUA_INCDIR}|" ${WRKSRC}/config
38
	${CP} ${FILESDIR}/doc.css ${WRKSRC}/doc/us
41
39
42
post-install:
40
post-install:
43
.if ${PORT_OPTIONS:MDOCS}
41
.if ${PORT_OPTIONS:MDOCS}
44
	${MKDIR} ${DOCSDIR} && \
42
	${MKDIR} ${STAGEDIR}${DOCSDIR} && \
45
	${CP} ${WRKSRC}/doc/us/* ${DOCSDIR}
43
	${CP} ${WRKSRC}/doc/us/* ${STAGEDIR}${DOCSDIR}
46
.endif
44
.endif
47
45
48
.include <bsd.port.mk>
46
.include <bsd.port.mk>
(-)luafilesystem/files/doc.css (+212 lines)
Line 0 Link Here
1
body { 
2
    margin-left: 1em; 
3
    margin-right: 1em; 
4
    font-family: arial, helvetica, geneva, sans-serif;
5
    background-color:#ffffff; margin:0px;
6
}
7
8
code {
9
    font-family: "Andale Mono", monospace; 
10
}
11
12
tt {
13
    font-family: "Andale Mono", monospace; 
14
}
15
16
body, td, th { font-size: 11pt; }
17
18
h1, h2, h3, h4 { margin-left: 0em; }
19
20
textarea, pre, tt { font-size:10pt; }
21
body, td, th { color:#000000; }
22
small { font-size:0.85em; }
23
h1 { font-size:1.5em; }
24
h2 { font-size:1.25em; }
25
h3 { font-size:1.15em; }
26
h4 { font-size:1.06em; }
27
28
a:link { font-weight:bold; color: #004080; text-decoration: none; }
29
a:visited { font-weight:bold; color: #006699; text-decoration: none; }
30
a:link:hover { text-decoration:underline; }
31
hr { color:#cccccc }
32
img { border-width: 0px; }
33
34
h3 { padding-top: 1em; }
35
36
p { margin-left: 1em; }
37
38
p.name { 
39
    font-family: "Andale Mono", monospace; 
40
    padding-top: 1em;
41
    margin-left: 0em; 
42
}
43
44
blockquote { margin-left: 3em; }
45
46
.example {
47
    background-color: rgb(245, 245, 245);
48
    border-top-width: 1px;
49
    border-right-width: 1px;
50
    border-bottom-width: 1px;
51
    border-left-width: 1px;
52
    border-top-style: solid;
53
    border-right-style: solid;
54
    border-bottom-style: solid;
55
    border-left-style: solid;
56
    border-top-color: silver;
57
    border-right-color: silver;
58
    border-bottom-color: silver;
59
    border-left-color: silver;
60
    padding: 1em;
61
    margin-left: 1em;
62
    margin-right: 1em;
63
    font-family: "Andale Mono", monospace; 
64
    font-size: smaller;
65
}
66
67
hr { 
68
    margin-left: 0em;
69
    background: #00007f; 
70
    border: 0px;
71
    height: 1px;
72
}
73
74
ul { list-style-type: disc; }
75
76
table.index { border: 1px #00007f; }
77
table.index td { text-align: left; vertical-align: top; }
78
table.index ul { padding-top: 0em; margin-top: 0em; }
79
80
table {
81
    border: 1px solid black;
82
    border-collapse: collapse;
83
    margin-left: auto;
84
    margin-right: auto;
85
}
86
87
th {
88
    border: 1px solid black;
89
    padding: 0.5em;
90
}
91
92
td {
93
    border: 1px solid black;
94
    padding: 0.5em;
95
}
96
div.header, div.footer { margin-left: 0em; }
97
98
#container {
99
    margin-left: 1em;
100
    margin-right: 1em;
101
    background-color: #f0f0f0;
102
}
103
104
#product {
105
    text-align: center;
106
    border-bottom: 1px solid #cccccc;
107
    background-color: #ffffff;
108
}
109
110
#product big {
111
    font-size: 2em;
112
}
113
114
#product_logo {
115
}
116
117
#product_name {
118
}
119
120
#product_description {
121
}
122
123
#main {
124
    background-color: #f0f0f0;
125
    border-left: 2px solid #cccccc;
126
}
127
128
#navigation {
129
    float: left;
130
    width: 12em;
131
    margin: 0;
132
    vertical-align: top;
133
    background-color: #f0f0f0;
134
    overflow:visible;
135
}
136
137
#navigation h1 {
138
    background-color:#e7e7e7;
139
    font-size:1.1em;
140
    color:#000000;
141
    text-align:left;
142
    margin:0px;
143
    padding:0.2em;
144
    border-top:1px solid #dddddd;
145
    border-bottom:1px solid #dddddd;
146
}
147
148
#navigation ul {
149
    font-size:1em;
150
    list-style-type: none;
151
    padding: 0;
152
    margin: 1px;
153
}
154
155
#navigation li {
156
    text-indent: -1em;
157
    margin: 0em 0em 0em 0.5em;
158
    display: block;
159
    padding: 3px 0px 0px 12px;
160
}
161
162
#navigation li li a {
163
    padding: 0px 3px 0px -1em;
164
}
165
166
#content {
167
    margin-left: 12em;
168
    padding: 1em;
169
    border-left: 2px solid #cccccc;
170
    border-right: 2px solid #cccccc;
171
    background-color: #ffffff;
172
}
173
174
#about {
175
    clear: both;
176
    margin: 0;
177
    padding: 5px;
178
    border-top: 2px solid #cccccc;
179
    background-color: #ffffff;
180
}
181
182
@media print {
183
    body {
184
        font: 10pt "Times New Roman", "TimeNR", Times, serif;
185
    }
186
    a {
187
        font-weight:bold; color: #004080; text-decoration: underline;
188
    }
189
    #main {
190
        background-color: #ffffff; border-left: 0px;
191
    }
192
    #container {
193
        margin-left: 2%; margin-right: 2%; background-color: #ffffff;
194
    }
195
    #content {
196
        margin-left: 0px; padding: 1em; border-left: 0px; border-right: 0px; background-color: #ffffff;
197
    }
198
    #navigation {
199
        display: none;
200
    }
201
    #product_logo {
202
        display: none;
203
    }
204
    #about img {
205
        display: none;
206
    }
207
    .example {
208
        font-family: "Andale Mono", monospace; 
209
        font-size: 8pt;
210
        page-break-inside: avoid;
211
    }
212
}
(-)luafilesystem/files/patch-doc__us__examples.html (+22 lines)
Line 0 Link Here
1
--- doc/us/examples.html	2009-10-21 00:54:35.000000000 +0400
2
+++ ../luafilesystem-master/doc/us/examples.html	2012-10-04 18:25:54.000000000 +0400
3
@@ -47,8 +47,8 @@
4
 		<li><strong>Examples</strong></li>
5
         <li><a href="http://luaforge.net/projects/luafilesystem/">Project</a>
6
             <ul>
7
-                <li><a href="http://luaforge.net/tracker/?group_id=66">Bug Tracker</a></li>
8
-                <li><a href="http://luaforge.net/scm/?group_id=66">CVS</a></li>
9
+                <li><a href="https://github.com/keplerproject/luafilesystem/issues">Bug Tracker</a></li>
10
+                <li><a href="https://github.com/keplerproject/luafilesystem">CVS</a></li>
11
             </ul>
12
         </li>
13
 		<li><a href="license.html">License</a></li>
14
@@ -65,7 +65,7 @@
15
 attributes for each file inside it.</p>
16
 
17
 <pre class="example">
18
-require"lfs"
19
+local lfs = require"lfs"
20
 
21
 function attrdir (path)
22
     for file in lfs.dir(path) do
(-)luafilesystem/files/patch-doc__us__index.html (+54 lines)
Line 0 Link Here
1
--- doc/us/index.html	2009-10-21 00:54:35.000000000 +0400
2
+++ ../luafilesystem-master/doc/us/index.html	2012-10-04 18:25:54.000000000 +0400
3
@@ -47,8 +47,8 @@
4
 		<li><a href="examples.html">Examples</a></li>
5
         <li><a href="http://luaforge.net/projects/luafilesystem/">Project</a>
6
             <ul>
7
-                <li><a href="http://luaforge.net/tracker/?group_id=66">Bug Tracker</a></li>
8
-                <li><a href="http://luaforge.net/scm/?group_id=66">CVS</a></li>
9
+                <li><a href="https://github.com/keplerproject/luafilesystem/issues">Bug Tracker</a></li>
10
+                <li><a href="https://github.com/keplerproject/luafilesystem">CVS</a></li>
11
             </ul>
12
         </li>
13
 		<li><a href="license.html">License</a></li>
14
@@ -71,7 +71,8 @@
15
 
16
 <h2><a name="status"></a>Status</h2>
17
 
18
-<p>Current version is 1.5.0. It was developed for Lua 5.1.</p>
19
+<p>Current version is 1.6.2. It was developed for Lua 5.1 but also
20
+  works with Lua 5.2.</p>
21
 
22
 <h2><a name="download"></a>Download</h2>
23
 
24
@@ -82,10 +83,30 @@
25
 <h2><a name="history"></a>History</h2>
26
 
27
 <dl class="history">
28
+	<dt><strong>Version 1.6.2</strong> [??/Oct/2012]</dt>
29
+	<dd><ul>
30
+        <li>Full Lua 5.2 compatibility (with Lua 5.1 fallbacks)</li>
31
+	</ul></dd>
32
+
33
+	<dt><strong>Version 1.6.1</strong> [01/Oct/2012]</dt>
34
+	<dd><ul>
35
+        <li>fix build for Lua 5.2</li>
36
+	</ul></dd>
37
+
38
+	<dt><strong>Version 1.6.0</strong> [26/Sep/2012]</dt>
39
+	<dd><ul>
40
+       <li>getcwd fix for Android</li>
41
+        <li>support for Lua 5.2</li>
42
+        <li>add lfs.link</li>
43
+        <li>other bug fixes</li>
44
+	</ul></dd>
45
+ 
46
 	<dt><strong>Version 1.5.0</strong> [20/Oct/2009]</dt>
47
+	<dd><ul>
48
 	<li>Added explicit next and close methods to second return value of lfs.dir 
49
 (the directory object), for explicit iteration or explicit closing.</li>
50
 	<li>Added directory locking via lfs.lock_dir function (see the <a href="manual.html">manual</a>).</li>
51
+	</ul></dd>
52
 	<dt><strong>Version 1.4.2</strong> [03/Feb/2009]</dt>
53
 	<dd>
54
 		<ul>
(-)luafilesystem/files/patch-doc__us__license.html (+13 lines)
Line 0 Link Here
1
--- doc/us/license.html	2009-10-21 00:54:35.000000000 +0400
2
+++ ../luafilesystem-master/doc/us/license.html	2012-10-04 18:25:54.000000000 +0400
3
@@ -47,8 +47,8 @@
4
 		<li><a href="examples.html">Examples</a></li>
5
         <li><a href="http://luaforge.net/projects/luafilesystem/">Project</a>
6
             <ul>
7
-                <li><a href="http://luaforge.net/tracker/?group_id=66">Bug Tracker</a></li>
8
-                <li><a href="http://luaforge.net/scm/?group_id=66">CVS</a></li>
9
+                <li><a href="https://github.com/keplerproject/luafilesystem/issues/">Bug Tracker</a></li>
10
+                <li><a href="https://github.com/keplerproject/luafilesystem">CVS</a></li>
11
             </ul>
12
         </li>
13
 		<li><strong>License</strong></li>
(-)luafilesystem/files/patch-doc__us__manual.html (+56 lines)
Line 0 Link Here
1
--- doc/us/manual.html	2009-10-21 00:54:35.000000000 +0400
2
+++ ../luafilesystem-master/doc/us/manual.html	2012-10-04 18:25:54.000000000 +0400
3
@@ -45,8 +45,8 @@
4
 		<li><a href="examples.html">Examples</a></li>
5
         <li><a href="http://luaforge.net/projects/luafilesystem/">Project</a>
6
             <ul>
7
-                <li><a href="http://luaforge.net/tracker/?group_id=66">Bug Tracker</a></li>
8
-                <li><a href="http://luaforge.net/scm/?group_id=66">CVS</a></li>
9
+                <li><a href="https://github.com/keplerproject/luafilesystem/issues">Bug Tracker</a></li>
10
+                <li><a href="https://github.com/keplerproject/luafilesystem">CVS</a></li>
11
             </ul>
12
         </li>
13
 		<li><a href="license.html">License</a></li>
14
@@ -174,7 +174,7 @@
15
 
16
     <dt><a name="chdir"></a><strong><code>lfs.lock_dir(path, [seconds_stale])</code></strong></dt>
17
     <dd>Creates a lockfile (called lockfile.lfs) in <code>path</code> if it does not
18
-  exist and returns the lock. If the lock already exists checks it
19
+  exist and returns the lock. If the lock already exists checks if
20
   it's stale, using the second parameter (default for the second
21
   parameter is <code>INT_MAX</code>, which in practice means the lock will never
22
   be stale. To free the the lock call <code>lock:free()</code>. <br/>
23
@@ -206,6 +206,13 @@
24
     Returns <code>true</code> if the operation was successful; in
25
     case of error, it returns <code>nil</code> plus an error string.
26
     </dd>
27
+
28
+    <dt><a name="link"></a><strong><code>lfs.link (old, new[, symlink])</code></strong></dt>
29
+    <dd>Creates a link. The first argument is the object to link to
30
+    and the second is the name of the link. If the optional third
31
+    argument is true, the link will by a symbolic link (by default, a
32
+    hard link is created).
33
+    </dd>
34
     
35
     <dt><a name="mkdir"></a><strong><code>lfs.mkdir (dirname)</code></strong></dt>
36
     <dd>Creates a new directory. The argument is the name of the new
37
@@ -221,15 +228,15 @@
38
 
39
     <dt><a name="setmode"></a><strong><code>lfs.setmode (file, mode)</code></strong></dt>
40
     <dd>Sets the writing mode for a file. The mode string can be either <code>binary</code> or <code>text</code>.
41
-    Returns the previous mode string for the file. This function is only available in Windows, so you may want to make sure that
42
-    <code>lfs.setmode</code> exists before using it.
43
+    Returns the previous mode string for the file. On non-Windows platforms, where the two modes are identical,
44
+    setting the mode has no effect, and the mode is always returned as <code>binary</code>.
45
     </dd>
46
     
47
     <dt><a name="symlinkattributes"></a><strong><code>lfs.symlinkattributes (filepath [, aname])</code></strong></dt>
48
     <dd>Identical to <a href="#attributes">lfs.attributes</a> except that
49
     it obtains information about the link itself (not the file it refers to).
50
-    This function is not available in Windows so you may want to make sure that
51
-    <code>lfs.symlinkattributes</code> exists before using it.
52
+    On Windows this function does not yet support links, and is identical to
53
+    <code>lfs.attributes</code>.
54
     </dd>
55
 
56
     <dt><a name="touch"></a><strong><code>lfs.touch (filepath [, atime [, mtime]])</code></strong></dt>
(-)luafilesystem/files/patch-src__lfs.c (+388 lines)
Line 0 Link Here
1
--- src/lfs.c	2009-10-21 00:54:35.000000000 +0400
2
+++ ../luafilesystem-master/src/lfs.c	2012-10-04 18:25:54.000000000 +0400
3
@@ -56,11 +56,19 @@
4
 #include <utime.h>
5
 #endif
6
 
7
-#include "lua.h"
8
-#include "lauxlib.h"
9
-#include "lualib.h"
10
+#include <lua.h>
11
+#include <lauxlib.h>
12
+#include <lualib.h>
13
+
14
 #include "lfs.h"
15
 
16
+#define LFS_VERSION "1.6.2"
17
+#define LFS_LIBNAME "lfs"
18
+
19
+#if LUA_VERSION_NUM < 502
20
+#  define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
21
+#endif
22
+
23
 /* Define 'strerror' for systems that do not implement it */
24
 #ifdef NO_STRERROR
25
 #define strerror(_)	"System unable to describe the error"
26
@@ -72,15 +80,22 @@
27
 #define getcwd_error	"Function 'getcwd' not provided by system"
28
 #else
29
 #define getcwd_error	strerror(errno)
30
+  #ifdef _WIN32
31
+	 /* MAX_PATH seems to be 260. Seems kind of small. Is there a better one? */
32
+    #define LFS_MAXPATHLEN MAX_PATH
33
+  #else
34
+	/* For MAXPATHLEN: */
35
+    #include <sys/param.h>
36
+    #define LFS_MAXPATHLEN MAXPATHLEN
37
+  #endif
38
 #endif
39
 
40
 #define DIR_METATABLE "directory metatable"
41
-#define MAX_DIR_LENGTH 1023
42
 typedef struct dir_data {
43
 	int  closed;
44
 #ifdef _WIN32
45
 	long hFile;
46
-	char pattern[MAX_DIR_LENGTH+1];
47
+        char pattern[MAX_PATH+1];
48
 #else
49
 	DIR *dir;
50
 #endif
51
@@ -97,17 +112,40 @@
52
   #define STAT_STRUCT struct _stati64
53
  #endif
54
 #define STAT_FUNC _stati64
55
+#define LSTAT_FUNC STAT_FUNC
56
 #else
57
 #define _O_TEXT               0
58
 #define _O_BINARY             0
59
-#define lfs_setmode(L,file,m)   ((void)((void)file,m),  \
60
-		 luaL_error(L, LUA_QL("setmode") " not supported on this platform"), -1)
61
+#define lfs_setmode(L,file,m)   ((void)L, (void)file, (void)m, 0)
62
 #define STAT_STRUCT struct stat
63
 #define STAT_FUNC stat
64
 #define LSTAT_FUNC lstat
65
 #endif
66
 
67
 /*
68
+** Utility functions
69
+*/
70
+static int pusherror(lua_State *L, const char *info)
71
+{
72
+        lua_pushnil(L);
73
+        if (info==NULL)
74
+                lua_pushstring(L, strerror(errno));
75
+        else
76
+                lua_pushfstring(L, "%s: %s", info, strerror(errno));
77
+        lua_pushinteger(L, errno);
78
+        return 3;
79
+}
80
+
81
+static int pushresult(lua_State *L, int i, const char *info)
82
+{
83
+        if (i==-1)
84
+                return pusherror(L, info);
85
+        lua_pushinteger(L, i);
86
+        return 1;
87
+}
88
+
89
+
90
+/*
91
 ** This function changes the working (current) directory
92
 */
93
 static int change_dir (lua_State *L) {
94
@@ -130,14 +168,15 @@
95
 */
96
 static int get_dir (lua_State *L) {
97
   char *path;
98
-  if ((path = getcwd(NULL, 0)) == NULL) {
99
+  /* Passing (NULL, 0) is not guaranteed to work. Use a temp buffer and size instead. */
100
+  char buf[LFS_MAXPATHLEN];
101
+  if ((path = getcwd(buf, LFS_MAXPATHLEN)) == NULL) {
102
     lua_pushnil(L);
103
     lua_pushstring(L, getcwd_error);
104
     return 2;
105
   }
106
   else {
107
     lua_pushstring(L, path);
108
-    free(path);
109
     return 1;
110
   }
111
 }
112
@@ -281,10 +320,9 @@
113
 }
114
 #endif
115
 
116
-#ifdef _WIN32
117
 static int lfs_g_setmode (lua_State *L, FILE *f, int arg) {
118
-  static const int mode[] = {_O_TEXT, _O_BINARY};
119
-  static const char *const modenames[] = {"text", "binary", NULL};
120
+  static const int mode[] = {_O_BINARY, _O_TEXT};
121
+  static const char *const modenames[] = {"binary", "text", NULL};
122
   int op = luaL_checkoption(L, arg, NULL, modenames);
123
   int res = lfs_setmode(L, f, mode[op]);
124
   if (res != -1) {
125
@@ -307,13 +345,6 @@
126
     return 3;
127
   }
128
 }
129
-#else
130
-static int lfs_g_setmode (lua_State *L, FILE *f, int arg) {
131
-  lua_pushboolean(L, 0);
132
-  lua_pushliteral(L, "setmode not supported on this platform");
133
-  return 2;
134
-}
135
-#endif
136
 
137
 static int lfs_f_setmode(lua_State *L) {
138
   return lfs_g_setmode(L, check_file(L, 1, "setmode"), 2);
139
@@ -363,14 +394,35 @@
140
 }
141
 
142
 
143
+/*
144
+** Creates a link.
145
+** @param #1 Object to link to.
146
+** @param #2 Name of link.
147
+** @param #3 True if link is symbolic (optional).
148
+*/
149
+static int make_link(lua_State *L)
150
+{
151
+#ifndef _WIN32
152
+        const char *oldpath = luaL_checkstring(L, 1);
153
+        const char *newpath = luaL_checkstring(L, 2);
154
+        return pushresult(L,
155
+                (lua_toboolean(L,3) ? symlink : link)(oldpath, newpath), NULL);
156
+#else
157
+        pusherror(L, "make_link is not supported on Windows");
158
+#endif
159
+}
160
+
161
+
162
+/*
163
+** Creates a directory.
164
+** @param #1 Directory path.
165
+*/
166
 static int make_dir (lua_State *L) {
167
 	const char *path = luaL_checkstring (L, 1);
168
 	int fail;
169
 #ifdef _WIN32
170
-	int oldmask = umask (0);
171
 	fail = _mkdir (path);
172
 #else
173
-	mode_t oldmask = umask( (mode_t)0 );
174
 	fail =  mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
175
 	                     S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH );
176
 #endif
177
@@ -379,7 +431,6 @@
178
         lua_pushfstring (L, "%s", strerror(errno));
179
 		return 2;
180
 	}
181
-	umask (oldmask);
182
 	lua_pushboolean (L, 1);
183
 	return 1;
184
 }
185
@@ -413,12 +464,13 @@
186
 	struct dirent *entry;
187
 #endif
188
 	dir_data *d = (dir_data *)luaL_checkudata (L, 1, DIR_METATABLE);
189
-	luaL_argcheck (L, !d->closed, 1, "closed directory");
190
+        luaL_argcheck (L, d->closed == 0, 1, "closed directory");
191
 #ifdef _WIN32
192
 	if (d->hFile == 0L) { /* first entry */
193
 		if ((d->hFile = _findfirst (d->pattern, &c_file)) == -1L) {
194
 			lua_pushnil (L);
195
 			lua_pushstring (L, strerror (errno));
196
+                        d->closed = 1;
197
 			return 2;
198
 		} else {
199
 			lua_pushstring (L, c_file.name);
200
@@ -457,14 +509,13 @@
201
 #ifdef _WIN32
202
 	if (!d->closed && d->hFile) {
203
 		_findclose (d->hFile);
204
-		d->closed = 1;
205
 	}
206
 #else
207
 	if (!d->closed && d->dir) {
208
 		closedir (d->dir);
209
-		d->closed = 1;
210
 	}
211
 #endif
212
+        d->closed = 1;
213
 	return 0;
214
 }
215
 
216
@@ -477,18 +528,16 @@
217
 	dir_data *d;
218
 	lua_pushcfunction (L, dir_iter);
219
 	d = (dir_data *) lua_newuserdata (L, sizeof(dir_data));
220
+        luaL_getmetatable (L, DIR_METATABLE);
221
+        lua_setmetatable (L, -2);
222
 	d->closed = 0;
223
 #ifdef _WIN32
224
 	d->hFile = 0L;
225
-	luaL_getmetatable (L, DIR_METATABLE);
226
-	lua_setmetatable (L, -2);
227
-	if (strlen(path) > MAX_DIR_LENGTH)
228
+        if (strlen(path) > MAX_PATH-2)
229
 		luaL_error (L, "path too long: %s", path);
230
 	else
231
 		sprintf (d->pattern, "%s/*", path);
232
 #else
233
-	luaL_getmetatable (L, DIR_METATABLE);
234
-	lua_setmetatable (L, -2);
235
 	d->dir = opendir (path);
236
 	if (d->dir == NULL)
237
 		luaL_error (L, "cannot open %s: %s", path, strerror (errno));
238
@@ -502,19 +551,18 @@
239
 */
240
 static int dir_create_meta (lua_State *L) {
241
 	luaL_newmetatable (L, DIR_METATABLE);
242
-	/* set its __gc field */
243
-	lua_pushstring (L, "__index");
244
+
245
+        /* Method table */
246
 	lua_newtable(L);
247
-	lua_pushstring (L, "next");
248
 	lua_pushcfunction (L, dir_iter);
249
-	lua_settable(L, -3);
250
-	lua_pushstring (L, "close");
251
+        lua_setfield(L, -2, "next");
252
 	lua_pushcfunction (L, dir_close);
253
-	lua_settable(L, -3);
254
-	lua_settable (L, -3);
255
-	lua_pushstring (L, "__gc");
256
+        lua_setfield(L, -2, "close");
257
+
258
+        /* Metamethods */
259
+        lua_setfield(L, -2, "__index");
260
 	lua_pushcfunction (L, dir_close);
261
-	lua_settable (L, -3);
262
+        lua_setfield (L, -2, "__gc");
263
 	return 1;
264
 }
265
 
266
@@ -523,10 +571,13 @@
267
 */
268
 static int lock_create_meta (lua_State *L) {
269
 	luaL_newmetatable (L, LOCK_METATABLE);
270
-	/* set its __gc field */
271
+
272
+        /* Method table */
273
 	lua_newtable(L);
274
 	lua_pushcfunction(L, lfs_unlock_dir);
275
 	lua_setfield(L, -2, "free");
276
+
277
+        /* Metamethods */
278
 	lua_setfield(L, -2, "__index");
279
 	lua_pushcfunction(L, lfs_unlock_dir);
280
 	lua_setfield(L, -2, "__gc");
281
@@ -669,6 +720,46 @@
282
 #endif
283
 }
284
 
285
+ /*
286
+** Convert the inode protection mode to a permission list.
287
+*/
288
+
289
+#ifdef _WIN32
290
+static const char *perm2string (unsigned short mode) {
291
+  static char perms[10] = "---------\0";
292
+  int i;
293
+  for (i=0;i<9;i++) perms[i]='-';
294
+  if (mode  & _S_IREAD)
295
+   { perms[0] = 'r'; perms[3] = 'r'; perms[6] = 'r'; }
296
+  if (mode  & _S_IWRITE)
297
+   { perms[1] = 'w'; perms[4] = 'w'; perms[7] = 'w'; }
298
+  if (mode  & _S_IEXEC)
299
+   { perms[2] = 'x'; perms[5] = 'x'; perms[8] = 'x'; }
300
+  return perms;
301
+}
302
+#else
303
+static const char *perm2string (mode_t mode) {
304
+  static char perms[10] = "---------\0";
305
+  int i;
306
+  for (i=0;i<9;i++) perms[i]='-';
307
+  if (mode & S_IRUSR) perms[0] = 'r';
308
+  if (mode & S_IWUSR) perms[1] = 'w';
309
+  if (mode & S_IXUSR) perms[2] = 'x';
310
+  if (mode & S_IRGRP) perms[3] = 'r';
311
+  if (mode & S_IWGRP) perms[4] = 'w';
312
+  if (mode & S_IXGRP) perms[5] = 'x';
313
+  if (mode & S_IROTH) perms[6] = 'r';
314
+  if (mode & S_IWOTH) perms[7] = 'w';
315
+  if (mode & S_IXOTH) perms[8] = 'x';
316
+  return perms;
317
+}
318
+#endif
319
+
320
+/* permssions string */
321
+static void push_st_perm (lua_State *L, STAT_STRUCT *info) {
322
+    lua_pushstring (L, perm2string (info->st_mode));
323
+}
324
+
325
 typedef void (*_push_function) (lua_State *L, STAT_STRUCT *info);
326
 
327
 struct _stat_members {
328
@@ -688,6 +779,7 @@
329
 	{ "modification", push_st_mtime },
330
 	{ "change",       push_st_ctime },
331
 	{ "size",         push_st_size },
332
+        { "permissions",  push_st_perm },
333
 #ifndef _WIN32
334
 	{ "blocks",       push_st_blocks },
335
 	{ "blksize",      push_st_blksize },
336
@@ -747,17 +839,9 @@
337
 /*
338
 ** Get symbolic link information using lstat.
339
 */
340
-#ifndef _WIN32
341
 static int link_info (lua_State *L) {
342
 	return _file_info_ (L, LSTAT_FUNC);
343
 }
344
-#else
345
-static int link_info (lua_State *L) {
346
-  lua_pushboolean(L, 0);
347
-  lua_pushliteral(L, "symlinkattributes not supported on this platform");
348
-  return 2;
349
-}
350
-#endif
351
 
352
 
353
 /*
354
@@ -765,13 +849,13 @@
355
 */
356
 static void set_info (lua_State *L) {
357
 	lua_pushliteral (L, "_COPYRIGHT");
358
-	lua_pushliteral (L, "Copyright (C) 2003-2009 Kepler Project");
359
+        lua_pushliteral (L, "Copyright (C) 2003-2012 Kepler Project");
360
 	lua_settable (L, -3);
361
 	lua_pushliteral (L, "_DESCRIPTION");
362
 	lua_pushliteral (L, "LuaFileSystem is a Lua library developed to complement the set of functions related to file systems offered by the standard Lua distribution");
363
 	lua_settable (L, -3);
364
 	lua_pushliteral (L, "_VERSION");
365
-	lua_pushliteral (L, "LuaFileSystem 1.5.0");
366
+        lua_pushliteral (L, "LuaFileSystem "LFS_VERSION);
367
 	lua_settable (L, -3);
368
 }
369
 
370
@@ -781,6 +865,7 @@
371
 	{"chdir", change_dir},
372
 	{"currentdir", get_dir},
373
 	{"dir", dir_iter_factory},
374
+        {"link", make_link},
375
 	{"lock", file_lock},
376
 	{"mkdir", make_dir},
377
 	{"rmdir", remove_dir},
378
@@ -795,7 +880,9 @@
379
 int luaopen_lfs (lua_State *L) {
380
 	dir_create_meta (L);
381
 	lock_create_meta (L);
382
-	luaL_register (L, "lfs", fslib);
383
+        luaL_newlib (L, fslib);
384
+        lua_pushvalue(L, -1);
385
+        lua_setglobal(L, LFS_LIBNAME);
386
 	set_info (L);
387
 	return 1;
388
 }
(-)luafilesystem/files/patch-src__lfs.h (+12 lines)
Line 0 Link Here
1
--- src/lfs.h.orig	2009-10-21 00:54:35.000000000 +0400
2
+++ src/lfs.h	2014-05-19 14:31:08.000000000 +0400
3
@@ -13,5 +13,9 @@
4
 #define chdir_error	strerror(errno)
5
 #endif
6
 
7
+// Fix for Lua-5.2
8
+#if LUA_VERSION_NUM == 502
9
+#	define luaL_reg	luaL_Reg
10
+#endif
11
 
12
 int luaopen_lfs (lua_State *L);

Return to bug 190105