Skip to content

Commit

Permalink
Merge pull request #100 from citrusleaf/CLIENT-597
Browse files Browse the repository at this point in the history
CLIENT-597 obey an explicit lua user_path
  • Loading branch information
rbotzer committed Dec 9, 2015
2 parents 9724ed6 + 7c5666d commit 6ff430d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/main/client/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ static int AerospikeClient_Type_Init(AerospikeClient * self, PyObject * args, Py
memcpy(config.lua.user_path, ".", AS_CONFIG_PATH_MAX_LEN);
} else {
struct stat info;
if (stat(config.lua.user_path, &info ) != 0 || !(info.st_mode & S_IFDIR) || (access(config.lua.user_path, W_OK) != 0)) {
if (stat(config.lua.user_path, &info ) != 0 || !(info.st_mode & S_IFDIR)) {
memcpy(config.lua.user_path, ".", AS_CONFIG_PATH_MAX_LEN);
}
}
Expand Down
49 changes: 30 additions & 19 deletions src/main/client/udf.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,36 @@ PyObject * AerospikeClient_UDF_Put(AerospikeClient * self, PyObject *args, PyObj

uint8_t * buff = bytes;

copy_file_p = fopen(copy_filepath, "r");
if (!copy_file_p) {
copy_file_p = fopen(copy_filepath, "w+");
int read = (int)fread(buff, 1, LUA_FILE_BUFFER_FRAME, file_p);
fwrite(buff, 1, read, copy_file_p);
while ( read ) {
size += read;
buff += read;
read = (int)fread(buff, 1, LUA_FILE_BUFFER_FRAME, file_p);
fwrite(buff, 1, read, copy_file_p);
}
} else {
int read = (int)fread(buff, 1, LUA_FILE_BUFFER_FRAME, file_p);
while ( read ) {
size += read;
buff += read;
read = (int)fread(buff, 1, LUA_FILE_BUFFER_FRAME, file_p);
}
}
if (access(self->as->config.lua.user_path, W_OK) == 0) {
copy_file_p = fopen(copy_filepath, "r");
if (!copy_file_p) {
copy_file_p = fopen(copy_filepath, "w+");
int read = (int)fread(buff, 1, LUA_FILE_BUFFER_FRAME, file_p);
if (read && fwrite(buff, 1, read, copy_file_p)) {
while (read) {
size += read;
buff += read;
read = (int)fread(buff, 1, LUA_FILE_BUFFER_FRAME, file_p);
if (!fwrite(buff, 1, read, copy_file_p)) {
break;
}
}
} else {
as_error_update(&err, AEROSPIKE_ERR_CLIENT, "Write of lua file to user path failed");
goto CLEANUP;
}
} else {
int read = (int)fread(buff, 1, LUA_FILE_BUFFER_FRAME, file_p);
while (read) {
size += read;
buff += read;
read = (int)fread(buff, 1, LUA_FILE_BUFFER_FRAME, file_p);
}
}
} else {
as_error_update(&err, AEROSPIKE_ERR_CLIENT, "No permissions to write lua file to user path");
goto CLEANUP;
}

if (file_p) {
fclose(file_p);
Expand Down
23 changes: 23 additions & 0 deletions test/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,26 @@ def user_callback(value):
except ClusterError as exception:
assert exception.code == 11L
assert exception.msg == 'No connection to aerospike cluster'

def test_aggregate_with_correct_parameters_lua_file_not_in_same_dir(self):
"""
Invoke aggregate() with correct arguments and lua file not in same
directory
"""
os.remove('stream_example.lua')
query = self.client.query('test', 'demo')
query.select('name', 'test_age')
query.where(p.between('test_age', 1, 5))
query.apply('stream_example', 'count')

records = []

def user_callback(value):
records.append(value)

query.foreach(user_callback)
assert records[0] == 4

assert True if os.path.isfile('/tmp/stream_example.lua') else False

shutil.move('/tmp/stream_example.lua', '.')

0 comments on commit 6ff430d

Please sign in to comment.