Updated Branches: refs/heads/master b91006082 -> 976db7893
Implement FSFolder_absolutify in core Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/976db789 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/976db789 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/976db789 Branch: refs/heads/master Commit: 976db78939edbc02b7c6b281c94a41d5b2c52aca Parents: 296f3a9 Author: Nick Wellnhofer <[email protected]> Authored: Tue Dec 4 20:32:08 2012 +0100 Committer: Nick Wellnhofer <[email protected]> Committed: Tue Dec 4 20:32:08 2012 +0100 ---------------------------------------------------------------------- c/src/Lucy/Store/FSFolder.c | 25 ------------ core/Lucy/Store/FSFolder.c | 56 ++++++++++++++++++++++++++- core/Lucy/Store/FSFolder.cfh | 5 -- example-lang/src/Lucy/Store/FSFolder.c | 25 ------------ perl/lib/Lucy.pm | 8 ---- perl/xs/Lucy/Store/FSFolder.c | 38 ------------------ ruby/src/Lucy/Store/FSFolder.c | 25 ------------ 7 files changed, 55 insertions(+), 127 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/976db789/c/src/Lucy/Store/FSFolder.c ---------------------------------------------------------------------- diff --git a/c/src/Lucy/Store/FSFolder.c b/c/src/Lucy/Store/FSFolder.c deleted file mode 100644 index df6ce19..0000000 --- a/c/src/Lucy/Store/FSFolder.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Lucy/Util/ToolSet.h" -#include "Lucy/Store/FSFolder.h" - -CharBuf* -FSFolder_absolutify(const CharBuf *path) { - THROW(LUCY_ERR, "TODO"); - UNREACHABLE_RETURN(lucy_CharBuf*); -} - http://git-wip-us.apache.org/repos/asf/lucy/blob/976db789/core/Lucy/Store/FSFolder.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Store/FSFolder.c b/core/Lucy/Store/FSFolder.c index 064f3fe..a59c16a 100644 --- a/core/Lucy/Store/FSFolder.c +++ b/core/Lucy/Store/FSFolder.c @@ -62,6 +62,14 @@ S_create_dir(const CharBuf *path); static bool S_is_local_entry(const CharBuf *path); +// Return true if the supplied path is absolute. +static bool +S_is_absolute(const CharBuf *path); + +// Transform a possibly relative path into an absolute path. +static CharBuf* +S_absolutify(const CharBuf *path); + // Create a hard link. static bool S_hard_link(CharBuf *from_path, CharBuf *to_path); @@ -74,7 +82,7 @@ FSFolder_new(const CharBuf *path) { FSFolder* FSFolder_init(FSFolder *self, const CharBuf *path) { - CharBuf *abs_path = FSFolder_absolutify(path); + CharBuf *abs_path = S_absolutify(path); Folder_init((Folder*)self, abs_path); DECREF(abs_path); return self; @@ -297,6 +305,35 @@ S_is_local_entry(const CharBuf *path) { #include <windows.h> static bool +S_is_absolute(const CharBuf *path) { + uint32_t code_point = CharBuf_Code_Point_At(path, 0); + + if (isalpha(code_point)) { + code_point = CharBuf_Code_Point_At(path, 1); + if (code_point != ':') { return false; } + code_point = CharBuf_Code_Point_At(path, 2); + } + + return code_point == '\\' || code_point == '/'; +} + +static CharBuf* +S_absolutify(const CharBuf *path) { + if (S_is_absolute(path)) { return Lucy_CB_Clone(path); } + + DWORD cwd_len = GetCurrentDirectory(0, NULL); + char *cwd = (char*)MALLOCATE(cwd_len); + DWORD res = GetCurrentDirectory(cwd_len, cwd); + if (res == 0 || res > cwd_len) { + THROW(ERR, "GetCurrentDirectory failed"); + } + CharBuf *abs_path = lucy_CB_newf("%s\\%o", cwd, path); + FREEMEM(cwd); + + return abs_path; +} + +static bool S_hard_link(CharBuf *from_path, CharBuf *to_path) { char *from8 = (char*)CB_Get_Ptr8(from_path); char *to8 = (char*)CB_Get_Ptr8(to_path); @@ -316,6 +353,23 @@ S_hard_link(CharBuf *from_path, CharBuf *to_path) { #elif (defined(CHY_HAS_UNISTD_H)) static bool +S_is_absolute(const CharBuf *path) { + return Lucy_CB_Starts_With_Str(path, DIR_SEP, 1); +} + +static CharBuf* +S_absolutify(const CharBuf *path) { + if (S_is_absolute(path)) { return Lucy_CB_Clone(path); } + + char *cwd = getcwd(NULL, 0); + if (!cwd) { THROW(ERR, "getcwd failed"); } + CharBuf *abs_path = lucy_CB_newf("%s%s%o", cwd, DIR_SEP, path); + free(cwd); + + return abs_path; +} + +static bool S_hard_link(CharBuf *from_path, CharBuf *to_path) { char *from8 = (char*)CB_Get_Ptr8(from_path); char *to8 = (char*)CB_Get_Ptr8(to_path); http://git-wip-us.apache.org/repos/asf/lucy/blob/976db789/core/Lucy/Store/FSFolder.cfh ---------------------------------------------------------------------- diff --git a/core/Lucy/Store/FSFolder.cfh b/core/Lucy/Store/FSFolder.cfh index 5ff916c..193db23 100644 --- a/core/Lucy/Store/FSFolder.cfh +++ b/core/Lucy/Store/FSFolder.cfh @@ -77,11 +77,6 @@ public class Lucy::Store::FSFolder inherits Lucy::Store::Folder { public bool Hard_Link(FSFolder *self, const CharBuf *from, const CharBuf *to); - - /** Transform a relative path into an abolute path. - */ - inert incremented CharBuf* - absolutify(const CharBuf *path); } http://git-wip-us.apache.org/repos/asf/lucy/blob/976db789/example-lang/src/Lucy/Store/FSFolder.c ---------------------------------------------------------------------- diff --git a/example-lang/src/Lucy/Store/FSFolder.c b/example-lang/src/Lucy/Store/FSFolder.c deleted file mode 100644 index df6ce19..0000000 --- a/example-lang/src/Lucy/Store/FSFolder.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Lucy/Util/ToolSet.h" -#include "Lucy/Store/FSFolder.h" - -CharBuf* -FSFolder_absolutify(const CharBuf *path) { - THROW(LUCY_ERR, "TODO"); - UNREACHABLE_RETURN(lucy_CharBuf*); -} - http://git-wip-us.apache.org/repos/asf/lucy/blob/976db789/perl/lib/Lucy.pm ---------------------------------------------------------------------- diff --git a/perl/lib/Lucy.pm b/perl/lib/Lucy.pm index a35e8f0..0466bcf 100644 --- a/perl/lib/Lucy.pm +++ b/perl/lib/Lucy.pm @@ -431,14 +431,6 @@ sub error {$Clownfish::Err::error} } { - package Lucy::Store::FSFolder; - our $VERSION = '0.003000'; - $VERSION = eval $VERSION; - use File::Spec::Functions qw( rel2abs ); - sub _absolutify {rel2abs(shift)} -} - -{ package Lucy::Store::RAMFileHandle; our $VERSION = '0.003000'; $VERSION = eval $VERSION; http://git-wip-us.apache.org/repos/asf/lucy/blob/976db789/perl/xs/Lucy/Store/FSFolder.c ---------------------------------------------------------------------- diff --git a/perl/xs/Lucy/Store/FSFolder.c b/perl/xs/Lucy/Store/FSFolder.c deleted file mode 100644 index 10d581c..0000000 --- a/perl/xs/Lucy/Store/FSFolder.c +++ /dev/null @@ -1,38 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "XSBind.h" -#include "Lucy/Store/FSFolder.h" - -cfish_CharBuf* -lucy_FSFolder_absolutify(const cfish_CharBuf *path) { - dSP; - ENTER; - SAVETMPS; - EXTEND(SP, 2); - PUSHMARK(SP); - mPUSHs(XSBind_cb_to_sv(path)); - PUTBACK; - call_pv("Lucy::Store::FSFolder::_absolutify", G_SCALAR); - SPAGAIN; - cfish_CharBuf *absolutified - = (cfish_CharBuf*)XSBind_perl_to_cfish(POPs); - PUTBACK; - FREETMPS; - LEAVE; - return absolutified; -} - http://git-wip-us.apache.org/repos/asf/lucy/blob/976db789/ruby/src/Lucy/Store/FSFolder.c ---------------------------------------------------------------------- diff --git a/ruby/src/Lucy/Store/FSFolder.c b/ruby/src/Lucy/Store/FSFolder.c deleted file mode 100644 index df6ce19..0000000 --- a/ruby/src/Lucy/Store/FSFolder.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Lucy/Util/ToolSet.h" -#include "Lucy/Store/FSFolder.h" - -CharBuf* -FSFolder_absolutify(const CharBuf *path) { - THROW(LUCY_ERR, "TODO"); - UNREACHABLE_RETURN(lucy_CharBuf*); -} -
