Erlang Mailing Lists

Author Message

<  Erlyweb mailing list  ~  bug: annoying double slash in function a/? when app root is

Guest
Posted: Wed Aug 06, 2008 7:40 pm Reply with quote
Guest
I'm not sure at the moment what the right approach would be. I'll have
to experiment with it a bit before I decide. I'm not too worried about
performance because these are very short strings. I think it's
reasonable to set the app root to "/" implicitly if the user hasn't
done so explicitly in the config file. The main problem is that
sometimes you want to redirect to an approot with a terminating "/" to
go back to the app's home page, but sometimes you want to redirect to
"/root" or something of that nature if the app root isn't "/", but
then you can't know a priori when navigating to a subdirectory if it
should be preceded by a "/" or not. If the app root is "/", you should
append to it "subdir" to go to "/subdir", but if the app root is
"/root", you should append to it "/subdir". Maybe the only solution is
to figure it out dynamically in runtime.

Yariv

On Tue, Aug 5, 2008 at 5:44 AM, Buggaboo <buggasnoo@gmail.com> wrote:
>
> I have come to the conclusion that removing the trailing slash from
> the app root is actually not a good idea. So please disregard what I
> said earlier about removing it.
>
> Although, my earlier comments about bugs arising in components with a
> magic components with regard to its approot being set to "/" are still
> valid. So if anyone has any sugestions, please reply.
>
> I have serious doubts whether my suggested replacement for
> get_app_root would be better.
> Since the reversal would incur a memory O(M + N + (M - N))-penalty.
> Yariv's would result in O(M-N) penalty... if I recall correctly how
> the function works, my function is easier on the eyes though. Since I
> don't know how the vm handles memory for stuff like this, a profiler
> could be handy.
>
> get_app_root (A) ->
> ServerPath = yaws_arg:server_path(A)
> , AppModData = yaws_arg:appmoddata(A)
> , lists:reverse(lists:reverse(ServerPath) --
> lists:reverse(AppModData)).
>
> vs.
>
> get_app_root(A) -
>>
> ServerPath =
> yaws_arg:server_path(A),
> L1 =
> length(ServerPath),
> L2 =
> length(yaws_arg:appmoddata(A)),
> if L2 > L1 ->
> "/";
> true ->
> {First, _Rest} =
> lists:split(
> length(ServerPath) - length(yaws_arg:appmoddata(A)),
> ServerPath),
> First
> end.
>
> Since the resulting value of both functions is not likely to change
> per app in run-time. This should be a constant.
>
> On Aug 4, 12:42 am, Buggaboo <buggas...@gmail.com> wrote:
>> Haha, the output should also be reversed Razz.
>>
>> On Aug 4, 12:40 am, Buggaboo <buggas...@gmail.com> wrote:
>>
>> > Hi,
>>
>> > My get_app_root patch could be simplified if one doesn't use the
>> > lists:split/? function.
>>
>> > Just do this:
>>
>> > get_app_root (A) ->
>> > ServerPath = yaws_arg:server_path(A)
>> > , AppModData = yaws_arg:appmoddata(A)
>> > , ServerPath -- AppModData.
>>
>> > This has a major problem.
>>
>> > Suppose the approot contains the string "abcd". Suppose there's a
>> > component also called "abcd".
>>
>> > "/abcdtest/abcd" -- "abcd". Guess which one gets removed. The intended
>> > effect is to remove the 2nd instance of "abcd" from left to right.
>>
>> > One could reverse both appmoddata and server_path, then subtract the
>> > reversed appmoddata from the server_path. That would solve the
>> > abovementioned problem. I think it could be cheaper and easier than
>> > the present solution provided by Yariv.
>>
>> > get_app_root (A) ->
>> > ServerPath = yaws_arg:server_path(A)
>> > , AppModData = yaws_arg:appmoddata(A)
>> > , lists:reverse(ServerPath) -- lists:reverse(AppModData).
>>
>> > The cheapest solution would be to store this value somewhere
>> > permanently... magically, like the magic model and magic controller.
>> > Yariv what do you think?
>>
>> > For instance:
>>
>> > erlyweb_<project>:get_constant()... like app_root, app_name etc.
>>
>> > Compute constants only once.
>>
>> > Bye.
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post received from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum